Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #71794 > unrolled thread
| Started by | Chad <cdalten@gmail.com> |
|---|---|
| First post | 2015-10-04 02:15 -0700 |
| Last post | 2015-10-05 05:49 +0200 |
| Articles | 14 — 7 participants |
Back to article view | Back to comp.lang.c
Do function arguments invoke a function? Chad <cdalten@gmail.com> - 2015-10-04 02:15 -0700
Re: Do function arguments invoke a function? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-04 08:09 -0400
Re: Do function arguments invoke a function? Chad <cdalten@gmail.com> - 2015-10-04 13:52 -0700
Re: Do function arguments invoke a function? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-04 17:13 -0400
Re: Do function arguments invoke a function? James Kuyper <jameskuyper@verizon.net> - 2015-10-04 17:13 -0400
Re: Do function arguments invoke a function? Geoff <geoff@invalid.invalid> - 2015-10-04 17:09 -0700
Re: Do function arguments invoke a function? Geoff <geoff@invalid.invalid> - 2015-10-04 17:10 -0700
Re: Do function arguments invoke a function? Chad <cdalten@gmail.com> - 2015-10-04 19:50 -0700
Re: Do function arguments invoke a function? James Kuyper <jameskuyper@verizon.net> - 2015-10-05 00:26 -0400
Re: Do function arguments invoke a function? James Kuyper <jameskuyper@verizon.net> - 2015-10-04 12:59 -0400
Re: Do function arguments invoke a function? James Kuyper <jameskuyper@verizon.net> - 2015-10-04 14:36 -0400
Re: Do function arguments invoke a function? jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-04 19:26 +0200
Re: Do function arguments invoke a function? Keith Thompson <kst-u@mib.org> - 2015-10-04 15:36 -0700
Re: Do function arguments invoke a function? Rosario19 <Ros@invalid.invalid> - 2015-10-05 05:49 +0200
| From | Chad <cdalten@gmail.com> |
|---|---|
| Date | 2015-10-04 02:15 -0700 |
| Subject | Do function arguments invoke a function? |
| Message-ID | <eaba057c-8bec-449a-8055-039f2c314655@googlegroups.com> |
In Java, when a method is called, the methods arguments invoke the method. Do functions in C do something similar? Chad
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-10-04 08:09 -0400 |
| Message-ID | <mur4qa$h7o$1@dont-email.me> |
| In reply to | #71794 |
On 10/4/2015 5:15 AM, Chad wrote:
> In Java, when a method is called, the methods arguments invoke the method. Do functions in C do something similar?
The arguments don't invoke the method or function, the call
operator invokes it. In both Java and C, the call operator is
written as a parenthesized list (possibly empty) of argument
expressions, immediately following a method reference (Java) or
function pointer expression (C).
func ()
^^^^ ^^
| call operator (no arguments)
|
function pointer
gunc (a, b, c)
^^^^ ^^^^^^^^^
| call operator (three arguments)
|
function pointer
(The term "call operator" is my own invention, as the Standard
doesn't actually refer to such an operator: It just says, in 6.5.2.2,
that the construct "is a function call." On the other hand, the
containing section 6.5.2 is titled "Postfix operators," so speaking
of a "function call operator" isn't entirely off-the-call, er, -wall.)
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Chad <cdalten@gmail.com> |
|---|---|
| Date | 2015-10-04 13:52 -0700 |
| Message-ID | <28cebd63-9869-4fa4-bcef-4f9acd2bed0d@googlegroups.com> |
| In reply to | #71795 |
The phrase "arguments invoke the function" is take directly from the Introduction to Java Programming by Y. Daniel Ling.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-10-04 17:13 -0400 |
| Message-ID | <mus4li$he6$1@dont-email.me> |
| In reply to | #71849 |
On 10/4/2015 4:52 PM, Chad wrote:
> The phrase "arguments invoke the function" is take directly from the Introduction to Java Programming by Y. Daniel Ling.
She's wrong, or she's not writing about what you think she is,
or she's been taken out of context. (Also, "function" is a strange
word to find in a Java text; Java has "methods.")
In both Java and C, consider the function or method call
yodel()
There are no arguments at all, yet the method or function is invoked
anyhow. If the arguments were the invokers, how could invocation
occur in the absence of arguments?
Perhaps she wrote that the argument *list* invokes the function,
and that would be about as reasonable as my "call operator" phrase,
and as sloppy. But the arguments themselves? I can't find much
enthusiasm for that wording, as it seems to me misleading.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2015-10-04 17:13 -0400 |
| Message-ID | <56119683.9030006@verizon.net> |
| In reply to | #71849 |
On 10/04/2015 04:52 PM, Chad wrote: > The phrase "arguments invoke the function" is take directly from the Introduction to Java Programming by Y. Daniel Ling. Could you give us the full context in which that phrase is used? It doesn't seem to make sense, but a better understanding of the context might change that.
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2015-10-04 17:09 -0700 |
| Message-ID | <iff31bleqbdfbukp23b0ug3svdesg6ndn9@4ax.com> |
| In reply to | #71849 |
On Sun, 4 Oct 2015 13:52:32 -0700 (PDT), Chad <cdalten@gmail.com> wrote: >The phrase "arguments invoke the function" is take directly from the Introduction to Java Programming by Y. Daniel Ling. I think you have misunderstood something he wrote in explaining method overloading. It would be nice if you could cite where the quotation appears in his book and to which edition you are referring. Java has classes, classes have methods, methods can be overloaded. This means two methods of a class can have the same name but take different number or types of arguments. The particular method to be called must be called according to the type or number of their arguments.
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2015-10-04 17:10 -0700 |
| Message-ID | <duf31bhru9v0qn93bgcv6ukpj4tplot1t7@4ax.com> |
| In reply to | #71849 |
On Sun, 4 Oct 2015 13:52:32 -0700 (PDT), Chad <cdalten@gmail.com> wrote: >Y. Daniel Ling His name is Y. Daniel Liang.
[toc] | [prev] | [next] | [standalone]
| From | Chad <cdalten@gmail.com> |
|---|---|
| Date | 2015-10-04 19:50 -0700 |
| Message-ID | <fe56446f-c47e-4950-8f15-5a1e4443343c@googlegroups.com> |
| In reply to | #71905 |
Section 5.5, near the bottom of page 163 "Listing 5.5 gives another program that demonstrates the effect of passing by value. The program creates a method for swapping two variables. The swap method is invoked by passing two arguments." And in section 11.7, near the middle of page 385 "Method displayObject (line 10) takes a parameter of the GeometricObject type. You can invoke displayObject by passing an instance if GeometricObject (e.g, new Circle4(1, "red", false) and new Rectangle(1, 1, "black", false) in lines 5-6)."
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2015-10-05 00:26 -0400 |
| Message-ID | <musu1o$l7q$1@dont-email.me> |
| In reply to | #71920 |
On 10/04/2015 10:50 PM, Chad wrote: > Section 5.5, near the bottom of page 163 > > "Listing 5.5 gives another program that demonstrates the effect of > passing by value. The program creates a method for swapping two > variables. The swap method is invoked by passing two arguments." Note: the swap method is not invoked by the two arguments, it is invoked by passing two arguments. What passes those two arguments? The code that calls the method. That code is itself part of some other method, so it is the calling method that does the passing, and it is therefore also the calling method that invokes the called method. > And in section 11.7, near the middle of page 385 > > "Method displayObject (line 10) takes a parameter of the > GeometricObject type. You can invoke displayObject by passing an > instance if GeometricObject (e.g, new Circle4(1, "red", false) and > new Rectangle(1, 1, "black", false) in lines 5-6)." Again, it is the passing of arguments that invokes the method, and not the arguments themselves. Getting back to your original question, corrected to reflect this distinction: yes, in C, functions which take arguments (not all of them do) can be invoked by passing such arguments to the called function. A function that takes no arguments can be invoked by passing it no arguments. I presume the same is true in Java? -- James Kuyper
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2015-10-04 12:59 -0400 |
| Message-ID | <56115B07.6070102@verizon.net> |
| In reply to | #71794 |
On 10/04/2015 05:15 AM, Chad wrote: > In Java, when a method is called, the methods arguments invoke the method. Do functions in C do something similar? Could you explain what that phrase "the method's arguments invoke the method" means to you? Knowing that, I might be able to answer with respect to C. As it stands, the phrase doesn't make sense to me. "arguments" are not actors, they are things that are acted on, so they can't, in themselves, invoke anything. Because of my experience, I tend to associate the term "method" with the C++ concept of a class member function - if the term has a significantly different meaning for Java, you should explain that meaning. C++ member functions are actors, and one of the actions they can perform is to call (invoke) another member function associated with the same object, or one associated with any other object that they have access to, and they can pass arguments to that other method. Possibly this understanding is C++-specific, and there's something in Java that makes it meaningful to talk about an argument invoking something. But if so, you'll have to explain that meaning, before I can answer your question.
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2015-10-04 14:36 -0400 |
| Message-ID | <561171C7.5060700@verizon.net> |
| In reply to | #71824 |
On 10/04/2015 01:19 PM, Stefan Ram wrote: > Newsgroups: comp.lang.c,comp.lang.java.programmer > > James Kuyper <jameskuyper@verizon.net> writes: >> On 10/04/2015 05:15 AM, Chad wrote: > >>> In Java, when a method is called, the methods arguments invoke the method. > ^^^^ thus the Newsgroups header! > >> Could you explain what that phrase "the method's arguments invoke the >> method" means to you? Knowing that, I might be able to answer with >> respect to C. As it stands, the phrase doesn't make sense to me. > > You are right! > > To »invoke« means to start, to execute, to run something. Arguments are > expressions that can be part of a method invocation expression. OK - it's just as true in C/C++ that the argument of a function can be the result of evaluating an expression. I hadn't thought of his question in those terms. In that sense, in C++ an argument expression can invoke methods associated with the objects involved in the expression, and can invoke methods associated with the same class that the calling method is associated with, even including another instance of the same method. However, they cannot be said, in any sense, to invoke the same instance of that method which they themselves are arguments of. It's the calling code that does that invocation, not the arguments. Evaluation of all method arguments must be complete, before evaluation of the method itself can start, so it's never the case that the arguments themselves invoke the instance of the method that they themselves are arguments to. Does Java have different rules in this regard that would make Chad's comment meaningful? > For example, in Java, the following is an expression: > > java.lang.Math.random() > > . This method invocation expression (JLS 15.12) has no arguments. > If the method's arguments would invoke the method, it would not > be invoked here, since there are no arguments. > > Moreover, a method does not have arguments in Java at all. It has > /parameters/. A /method invocation expression/ has arguments. That distinction applies to C/C++ as well.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2015-10-04 19:26 +0200 |
| Message-ID | <murnbn$p9p$1@dont-email.me> |
| In reply to | #71794 |
Le 04/10/2015 11:15, Chad a écrit : > In Java, when a method is called, the methods arguments invoke the method. Do functions in C do something similar? > > Chad > In C, if you call sin(x) the "sin" generic function will resolve into different functions: sinl() if x is long double, or csin, if x is a complex number. This is defined in the standard header <tgmath.h>. In the lcc-win compiler you can mark functions as "overloaded", i.e. it consists of a table of several functions that are called according to the set of arguments of the call, the "signature". For instance you can write programs that are indepenent of the specific type of number they are dealing with, making possible to have several versions of the same code with a single source. Or you can abstract certain actions with abstract interfaces that are valid for a set of slightly different types. In C++ all functions are actually "overloaded", in the lcc-win implementation only those explicitely marked so. And since no function is overloaded by default you can still have error messages from the compiler when you make a call with the wrong arguments. Not from the linker complaining because of a missing overload. But I am biased of course.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-10-04 15:36 -0700 |
| Message-ID | <ln612mxnuh.fsf@kst-u.example.com> |
| In reply to | #71794 |
Chad <cdalten@gmail.com> writes:
> In Java, when a method is called, the methods arguments invoke the
> method. Do functions in C do something similar?
As others have suggested, that statement about Java doesn't seem to make
sense.
The Java Language Specification describes run-time method invocation as
a 5-step process. Evaluating the arguments is step 2; transferring
control is step 5.
I'm no expert on Java, so perhaps I'm missing something. In any case,
it doesn't make sense in C.
A C function call evalautes the prefix (which is usually just a funciton
name), evaluates the arguments, and invokes the function. Invoking the
function assigns the argument values to the parameters before the body
of the function starts executing.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Rosario19 <Ros@invalid.invalid> |
|---|---|
| Date | 2015-10-05 05:49 +0200 |
| Message-ID | <0ks31b94gmv5eciv1v3t4fhgn5fkdtahum@4ax.com> |
| In reply to | #71794 |
On Sun, 4 Oct 2015 02:15:03 -0700 (PDT), Chad wrote: >In Java, when a method is called, >the methods arguments invoke the method. >Do functions in C do something similar? no in C there is not overload as C++ and Java [i presume] for invoke one function is significative only the name not the args >Chad
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web