470,874 Members | 1,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

Question on Wording

Hello all,

I am trying to understand in detail the correct wording to use in C
for teaching purposes.
For the example:
int foo(int x, int y) {
int k;
...
return k;
}

you could call foo a function or a procedure. On this matter I guess
that the choice is function (K&R2 and C99 standard) given there's no
occurrences of the word procedure there as far as I can tell. Still,
it is unfortunate because you need to explain that these functions are
not in the mathematical sense and so on but it's not a huge issue.

On the other hand, what do you call x? Is it an argument or a parameter?
K&R2 seems to mention both words and I couldn't spot the difference. I
would then assume that "int x, int y" is the argument list/ parameter
list according to what x and y are. But which wording to use?

Moreover, I presented the function definition. The function
declaration would be:
int foo(int x, int y);

but, what if I present the function definition and want to refer only
to the part before the body of the function (compound statement as far
as C99 is concerned)? Shall I call it function declaration (seems
ambiguous since I already used function declaration above) or function
header (this one might create confusion with header files).

I would appreciate input on this.

Best Regards,

--
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
Jun 27 '08 #1
14 1165
Paulo Jorge de O. C. de Matos wrote:
Hello all,

I am trying to understand in detail the correct wording to use in C
for teaching purposes.
For the example:
int foo(int x, int y) {
int k;
...
return k;
}

you could call foo a function or a procedure. On this matter I guess
that the choice is function (K&R2 and C99 standard) given there's no
occurrences of the word procedure there as far as I can tell. Still,
it is unfortunate because you need to explain that these functions are
not in the mathematical sense and so on but it's not a huge issue.

On the other hand, what do you call x? Is it an argument or a
parameter? K&R2 seems to mention both words and I couldn't spot the
difference. I would then assume that "int x, int y" is the argument
list/ parameter
list according to what x and y are. But which wording to use?
I would use the word arguments for the actual expressions used within
the parenthesis in a call to a function and use the word parameter to
designate the same in a function declaration.

<http://en.wikipedia.org/wiki/Parameter_%28computer_science%29>

An alternative is use "formal parameter" and "actual parameter" but
that's cumbersome for quick communication.
Moreover, I presented the function definition. The function
declaration would be:
int foo(int x, int y);

but, what if I present the function definition and want to refer only
to the part before the body of the function (compound statement as far
as C99 is concerned)? Shall I call it function declaration (seems
ambiguous since I already used function declaration above) or function
header (this one might create confusion with header files).
It's a syntax error to present a function definition without it's
associated brace pairs or to present a function declaration without
it's terminating semicolon, there I suggest that you always use either:

T foo(T param) {}

or

T foo(T param);

when presenting examples. If you do want to use a name for it, then
function header seems the most suitable to me. Maybe someone else will
suggest something more correct or better.

Jun 27 '08 #2
Paulo Jorge de O. C. de Matos wrote:
Hello all,

I am trying to understand in detail the correct wording to use in C
for teaching purposes.
For the example:
int foo(int x, int y) {
int k;
...
return k;
}

you could call foo a function or a procedure. On this matter I guess
that the choice is function (K&R2 and C99 standard) given there's no
occurrences of the word procedure there as far as I can tell. Still,
it is unfortunate because you need to explain that these functions are
not in the mathematical sense and so on but it's not a huge issue.

On the other hand, what do you call x? Is it an argument or a parameter?
K&R2 seems to mention both words and I couldn't spot the difference. I
would then assume that "int x, int y" is the argument list/ parameter
list according to what x and y are. But which wording to use?
The "parameters" or "formal parameters" are `x' and `y'.
The "arguments" are the values provided by the caller.

... but not all speakers and writers are careful to make
the distinction, so the terms are often (mis)used as if they
meant the same thing. It's the same kind of loose language
as when we say "The argument to strlen() is a string" or
"is a pointer to a string;" it would be more precise to call
it "a pointer to the first char of a string," but it would
also be more tedious to maintain the exactness.
Moreover, I presented the function definition. The function
declaration would be:
int foo(int x, int y);
Or just `int foo(int, int);'. And in pursuit of precision
it might be well to note that the `;' is not part of the
declaration. For example, consider

int foo(int, int), bar(double), baz(int, const char*);

.... a style I would not ordinarily use, but which is legal.
but, what if I present the function definition and want to refer only
to the part before the body of the function (compound statement as far
as C99 is concerned)? Shall I call it function declaration (seems
ambiguous since I already used function declaration above) or function
header (this one might create confusion with header files).
I don't know what advice to offer. The formal grammar of
the language does not define one symbol that encompasses all
and only that part of the definition, so the Standard is no
help in coming up with a suitable name. How pressing is your
need to refer to this part as a quasi-independent unit, rather
than as the introductory part of the function definition? I
guess "preamble" would be as good a word as any, if one must
be found.

I'd avoid "declaration" and "header" for the reasons you
mention, and also because in an old-style function definition
this part can *contain* declarations:

int foo(x, y)
int x; /* declaration */
int y; /* declaration */
{ ... }

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jun 27 '08 #3
Paulo Jorge de O. C. de Matos said:
Hello all,

I am trying to understand in detail the correct wording to use in C
for teaching purposes.
For the example:
int foo(int x, int y) {
int k;
...
return k;
}

you could call foo a function or a procedure. On this matter I guess
that the choice is function (K&R2 and C99 standard)
Right. That isn't just K&R/C99 terminology - it's general C programmer
terminology too. I've never heard a "real C programmer" (cf "True
Scotsman") call it a procedure.
On the other hand, what do you call x? Is it an argument or a parameter?
It's a parameter.

Here's an argument:

rc = function(argument_expressions_are_what_you_pass);

Here's a parameter:

int function(char *parameters_are_what_the_function_receives)

Think of a door. On this side is painted "argument". Open it, step through,
and close it. On the other side, you will see "parameter" (in large,
friendly letters). Note that you are now a copy of yourself.
Moreover, I presented the function definition. The function
declaration would be:
int foo(int x, int y);

but, what if I present the function definition and want to refer only
to the part before the body of the function (compound statement as far
as C99 is concerned)?
It's called a "function declarator".

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #4
Paulo Jorge de O. C. de Matos wrote:
Hello all,

I am trying to understand in detail the correct wording to use in C
for teaching purposes.
For the example:
int foo(int x, int y) {
int k;
...
return k;
}

you could call foo a function or a procedure. On this matter I guess
that the choice is function (K&R2 and C99 standard) given there's no
occurrences of the word procedure there as far as I can tell. Still,
it is unfortunate because you need to explain that these functions are
not in the mathematical sense and so on but it's not a huge issue.
An "appendectomy" is a "procedure".
Most, if not all, of the words defined in the standard
have different meanings in standard English.
On the other hand, what do you call x? Is it an argument or a parameter?
K&R2 seems to mention both words and I couldn't spot the difference. I
would then assume that "int x, int y" is the argument list/ parameter
list according to what x and y are. But which wording to use?

Moreover, I presented the function definition. The function
declaration would be:
int foo(int x, int y);

but, what if I present the function definition and want to refer only
to the part before the body of the function (compound statement as far
as C99 is concerned)? Shall I call it function declaration (seems
ambiguous since I already used function declaration above) or function
header (this one might create confusion with header files).

I would appreciate input on this.
Parameters are the objects declared in a function prototype.
Arguments are the values in a function call
which are used to initialize the parameters.

Considering new.c:

/* BEGIN new.c */

int sum(int x, int y)
{
return x + y;
}

int main(void)
{

int j = 5;

return sum(-5, j);
}

/* END new.c */

In the definition of main, in the function call to sum,
-5 is an argument.
j is a argument.

In the definition of sum,
x and y are both parameters.

--
pete
Jun 27 '08 #5
On Apr 26, 8:21 am, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
Paulo Jorge de O. C. de Matos wrote:
Hello all,
I am trying to understand in detail the correct wording to use in C
for teaching purposes.
For the example:
int foo(int x, int y) {
int k;
...
return k;
}
you could call foo a function or a procedure. On this matter I guess
that the choice is function (K&R2 and C99 standard) given there's no
occurrences of the word procedure there as far as I can tell. Still,
it is unfortunate because you need to explain that these functions are
not in the mathematical sense and so on but it's not a huge issue.
On the other hand, what do you call x? Is it an argument or a parameter?
K&R2 seems to mention both words and I couldn't spot the difference. I
would then assume that "int x, int y" is the argument list/ parameter
list according to what x and y are. But which wording to use?

The "parameters" or "formal parameters" are `x' and `y'.
The "arguments" are the values provided by the caller.

... but not all speakers and writers are careful to make
the distinction, so the terms are often (mis)used as if they
meant the same thing. It's the same kind of loose language
as when we say "The argument to strlen() is a string" or
"is a pointer to a string;" it would be more precise to call
it "a pointer to the first char of a string," but it would
also be more tedious to maintain the exactness.
Moreover, I presented the function definition. The function
declaration would be:
int foo(int x, int y);

Or just `int foo(int, int);'. And in pursuit of precision
it might be well to note that the `;' is not part of the
declaration.
Yes it is.
For example, consider

int foo(int, int), bar(double), baz(int, const char*);

... a style I would not ordinarily use, but which is legal.
The whole thing is a declaration.
>
but, what if I present the function definition and want to refer only
to the part before the body of the function (compound statement as far
as C99 is concerned)? Shall I call it function declaration (seems
ambiguous since I already used function declaration above) or function
header (this one might create confusion with header files).

I don't know what advice to offer. The formal grammar of
the language does not define one symbol that encompasses all
and only that part of the definition, so the Standard is no
help in coming up with a suitable name. How pressing is your
need to refer to this part as a quasi-independent unit, rather
than as the introductory part of the function definition? I
guess "preamble" would be as good a word as any, if one must
be found.

I'd avoid "declaration" and "header" for the reasons you
mention, and also because in an old-style function definition
this part can *contain* declarations:

int foo(x, y)
int x; /* declaration */
int y; /* declaration */
{ ... }
int func(int a) - it contains a declaration too, of the
parameter a. It's not called "declaration" in the grammar
yet it declares the parameter (and you'd probably have
hard time pronouncing dash in the "parameter-declaration").
"Function declarator" is good and standard, except one
would need to be silent about old-style parameter declarations
so they don't spoil the picture :)
One needs "declarator" if he wants to explain array
and function pointer declarations anyway.

Yevgen
Jun 27 '08 #6
Eric Sosman <es*****@ieee-dot-org.invalidwrites:
[...]
The "parameters" or "formal parameters" are `x' and `y'.
The "arguments" are the values provided by the caller.

... but not all speakers and writers are careful to make
the distinction, so the terms are often (mis)used as if they
meant the same thing. It's the same kind of loose language
as when we say "The argument to strlen() is a string" or
"is a pointer to a string;" it would be more precise to call
it "a pointer to the first char of a string," but it would
also be more tedious to maintain the exactness.
[...]

Except that the phrase "pointer to a string" is perfectly correct and
unambiguous. See C99 7.1.1p1:

A _string_ is a contiguous sequence of characters terminated by
and including the first null character. [...] A _pointer to a
string_ is a pointer to its initial (lowest addressed) character.

There's a related error of referring to a pointer to the first element
of an array as a pointer to the array; that's wrong, because a pointer
to an array is a distinct entity of a different type. But since a
string is a data format, not a data type, the standard was free to
provide a definition for the otherwise meaningles phrase "pointer to a
string".

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #7
mu*****@gmail.com wrote:
On Apr 26, 8:21 am, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>>
Or just `int foo(int, int);'. And in pursuit of precision
it might be well to note that the `;' is not part of the
declaration.

Yes it is.
Thank you for the correction; I was wrong. (Section 6.7,
paragraph 1)

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jun 27 '08 #8
On Sat, 26 Apr 2008 18:43:05 +0530, santosh <sa*********@gmail.com>
wrote in comp.lang.c:
Paulo Jorge de O. C. de Matos wrote:
Hello all,

I am trying to understand in detail the correct wording to use in C
for teaching purposes.
For the example:
int foo(int x, int y) {
int k;
...
return k;
}

you could call foo a function or a procedure. On this matter I guess
that the choice is function (K&R2 and C99 standard) given there's no
occurrences of the word procedure there as far as I can tell. Still,
it is unfortunate because you need to explain that these functions are
not in the mathematical sense and so on but it's not a huge issue.

On the other hand, what do you call x? Is it an argument or a
parameter? K&R2 seems to mention both words and I couldn't spot the
difference. I would then assume that "int x, int y" is the argument
list/ parameter
list according to what x and y are. But which wording to use?

I would use the word arguments for the actual expressions used within
the parenthesis in a call to a function and use the word parameter to
designate the same in a function declaration.

<http://en.wikipedia.org/wiki/Parameter_%28computer_science%29>

An alternative is use "formal parameter" and "actual parameter" but
that's cumbersome for quick communication.
Moreover, I presented the function definition. The function
declaration would be:
int foo(int x, int y);

but, what if I present the function definition and want to refer only
to the part before the body of the function (compound statement as far
as C99 is concerned)? Shall I call it function declaration (seems
ambiguous since I already used function declaration above) or function
header (this one might create confusion with header files).

It's a syntax error to present a function definition without it's
associated brace pairs or to present a function declaration without
it's terminating semicolon, there I suggest that you always use either:
No, this is not correct. All of these are function declarations:

1. int foo();

2. int foo(int, int);

3. int foo(x, y)
int x, y;
{ return x + y; }

4. int foo(int x, int y)
{ return x + y; }

It is impossible to define a function without also declaring it, to 3.
and 4. are function declarations as well as definitions. In addition
to being a definition, 3. is a declaration but not a prototype, 4. is
a all of a declaration, a prototype, and a definition.

1. and 2. are declarations that are not definitions, 2. is also a
prototype.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jun 27 '08 #9
Jack Klein wrote:
On Sat, 26 Apr 2008 18:43:05 +0530, santosh <sa*********@gmail.com>
wrote in comp.lang.c:
>Paulo Jorge de O. C. de Matos wrote:
Hello all,

I am trying to understand in detail the correct wording to use in C
for teaching purposes.
For the example:
int foo(int x, int y) {
int k;
...
return k;
}

you could call foo a function or a procedure. On this matter I
guess that the choice is function (K&R2 and C99 standard) given
there's no occurrences of the word procedure there as far as I can
tell. Still, it is unfortunate because you need to explain that
these functions are not in the mathematical sense and so on but
it's not a huge issue.

On the other hand, what do you call x? Is it an argument or a
parameter? K&R2 seems to mention both words and I couldn't spot the
difference. I would then assume that "int x, int y" is the argument
list/ parameter
list according to what x and y are. But which wording to use?

I would use the word arguments for the actual expressions used within
the parenthesis in a call to a function and use the word parameter to
designate the same in a function declaration.

<http://en.wikipedia.org/wiki/Parameter_%28computer_science%29>

An alternative is use "formal parameter" and "actual parameter" but
that's cumbersome for quick communication.
Moreover, I presented the function definition. The function
declaration would be:
int foo(int x, int y);

but, what if I present the function definition and want to refer
only to the part before the body of the function (compound
statement as far as C99 is concerned)? Shall I call it function
declaration (seems ambiguous since I already used function
declaration above) or function header (this one might create
confusion with header files).

It's a syntax error to present a function definition without it's
associated brace pairs or to present a function declaration without
it's terminating semicolon, there I suggest that you always use
either:

No, this is not correct. All of these are function declarations:

1. int foo();

2. int foo(int, int);

3. int foo(x, y)
int x, y;
{ return x + y; }

4. int foo(int x, int y)
{ return x + y; }

It is impossible to define a function without also declaring it, to 3.
and 4. are function declarations as well as definitions. In addition
to being a definition, 3. is a declaration but not a prototype, 4. is
a all of a declaration, a prototype, and a definition.

1. and 2. are declarations that are not definitions, 2. is also a
prototype.
Thank you very much.

Jun 27 '08 #10
Paulo Jorge de O. C. de Matos writes:
On this matter I guess
that the choice is function (K&R2 and C99 standard) given there's no
occurrences of the word procedure there as far as I can tell. Still,
it is unfortunate because you need to explain that these functions are
not in the mathematical sense and so on but it's not a huge issue.
Turn it around, into a lecture about the importance of programmer
discipline, trying to be consistent about function parameters, etc.

"Code to execute in C is put in 'functions'. They don't resemble
mathematical functions all that much though. A function can modify what
its parameters point at or global variables, but whether it does so is
not expressed in the function declaration. It can have return type void
which means it doesn't return anything. Some other languages would call
that it a procedure, but as far as C is concerned it's a function. If a
function does return a value, the caller is free to ignore it - even
when doing so would be a bug in the program.

So it's the programmer's job to try to make it visible what is going on,
in particular which function call may modify what. One could e.g. try
to normally make modifiable parameters the first parameters. If a
function needs to return several values, don't just pick any one of them
as the "real" return value and pass the address of the other as a
parameter - it might be more readable to pass the address of both as
parameters, and return nothing or return an error indication. ...etc..."

--
Hallvard
Jun 27 '08 #11
Eric Sosman wrote:
mu*****@gmail.com wrote:
>On Apr 26, 8:21 am, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>>>
Or just `int foo(int, int);'. And in pursuit of precision
it might be well to note that the `;' is not part of the
declaration.

Yes it is.

Thank you for the correction; I was wrong. (Section 6.7,
paragraph 1)
I recall once,
that upon my mentioning that function definitions
are the only declarations that are not semicolon terminated,
that it was pointed out to me that function definitions
do not fit the standard's description of what declarations are.

I believe that it is because function definitions
are not semicolon terminated.

--
pete
Jun 27 '08 #12
On Sun, 27 Apr 2008 07:24:54 -0500, pete wrote:
Eric Sosman wrote:
>mu*****@gmail.com wrote:
>>On Apr 26, 8:21 am, Eric Sosman <esos...@ieee-dot-org.invalidwrote:

Or just `int foo(int, int);'. And in pursuit of precision
it might be well to note that the `;' is not part of the declaration.

Yes it is.

Thank you for the correction; I was wrong. (Section 6.7,
paragraph 1)

I recall once,
that upon my mentioning that function definitions are the only
declarations that are not semicolon terminated, that it was pointed out
to me that function definitions do not fit the standard's description of
what declarations are.

I believe that it is because function definitions are not semicolon
terminated.
It's because function definitions are not allowed inside of another
function. A translation unit is made up of declarations, mixed with
function definitions. Declarations may be omitted, function definitions
may be omitted, but at least one of either must be present. This could
have been specified as

translation-unit:
declaration
function-definition
translation-unit declaration
translation-unit function-definition

but it's just as easy to specify it as

translation-unit:
declaration-or-function-definition
translation-unit declaration-or-function-definition
Jun 27 '08 #13
On Sun, 27 Apr 2008 14:33:32 +0200, Harald van Dijk wrote:
On Sun, 27 Apr 2008 07:24:54 -0500, pete wrote:
>Eric Sosman wrote:
>>mu*****@gmail.com wrote:
On Apr 26, 8:21 am, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>
Or just `int foo(int, int);'. And in pursuit of precision
it might be well to note that the `;' is not part of the
declaration.

Yes it is.

Thank you for the correction; I was wrong. (Section 6.7,
paragraph 1)

I recall once,
that upon my mentioning that function definitions are the only
declarations that are not semicolon terminated, that it was pointed out
to me that function definitions do not fit the standard's description
of what declarations are.

I believe that it is because function definitions are not semicolon
terminated.

It's because function definitions are not allowed inside of another
function. A translation unit is made up of declarations, mixed with
function definitions. Declarations may be omitted, function definitions
may be omitted, but at least one of either must be present. This could
have been specified as

translation-unit:
declaration
function-definition
translation-unit declaration
translation-unit function-definition

but it's just as easy to specify it as

translation-unit:
declaration-or-function-definition
translation-unit declaration-or-function-definition
Apologies, I hit Send too soon.

declaration-or-function-definition was named external-declaration, which
just means that:

external-declaration:
declaration
function-definition

The alternative would have been to make function-definition a part of
declarations directly: it's now

declaration:
declaration-specifiers init-declarator-list/opt/ ;

and it would become

declaration:
declaration-specifiers init-declarator-list/opt/ ;
function-definition

However, doing this would syntactically allow function definitions
_anywhere_ declarations are allowed. In particular, it would allow
function definitions inside of other function definitions. While it could
then be explicitly prohibited, it's as easy to simply not allow them in
the first place.
Jun 27 '08 #14
On Sat, 26 Apr 2008 13:31:20 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
Paulo Jorge de O. C. de Matos said:
I am trying to understand in detail the correct wording to use in C
for teaching purposes. <snip>
you could call foo a function or a procedure. On this matter I guess
that the choice is function (K&R2 and C99 standard)

Right. That isn't just K&R/C99 terminology - it's general C programmer
terminology too. <snip>
Concur.
On the other hand, what do you call x? Is it an argument or a parameter?

It's a parameter. ... Here's an argument: [in the call]
<PythonNo it isn't. Yes it is. No it isn't, mere contradiction is
not an argument. </Seriously, concur.
but, what if I present the function definition and want to refer only
to the part before the body of the function (compound statement as far
as C99 is concerned)?
(It was already a compound-statement in C89.)
It's called a "function declarator".
Not quite. The function declarator is foo(int x,int y) or foo(x,y) and
does not include the (return) type-specifier(s) mandatory in C99 and
optional-recommended in C89, and the 'storage-class' (linkage) if any.
And for more complicated return types, it leaves out more; the
standardly convenient infamous example is signal().

I think the OP is correct there is no good common syntax term for just
the 'visible' (to file scope) part of the function definition. I would
use 'function header' in spite of the drawback he mentioned;
'preamble' just doesn't feel right to me. OTOH the _semantics_ of this
element, namely the (full) type declared for the function, is commonly
(though not standardly) called the signature, a term which has the
advantage of not being used for anything else in this area.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Jun 27 '08 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Ioannis Vranos | last post: by
5 posts views Thread by Paul F. Dietz | last post: by
7 posts views Thread by heddy | last post: by
19 posts views Thread by Leslie Kis-Adam | last post: by
19 posts views Thread by Andrew Gentile | last post: by
30 posts views Thread by Brian | last post: by
16 posts views Thread by Donn Ingle | last post: by
39 posts views Thread by Juha Nieminen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.