Velocity Reviews > Question on Wording

# Question on Wording

Paulo Jorge de O. C. de Matos
Guest
Posts: n/a

 04-26-2008
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

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

santosh
Guest
Posts: n/a

 04-26-2008
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

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.

muntyan@gmail.com
Guest
Posts: n/a

 04-26-2008
On Apr 26, 8:21 am, Eric Sosman <(E-Mail Removed)> wrote:
> 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

>
> 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

Keith Thompson
Guest
Posts: n/a

 04-26-2008
Eric Sosman <(E-Mail Removed)> writes:
[...]
> 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) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

santosh
Guest
Posts: n/a

 04-27-2008
Jack Klein wrote:

> On Sat, 26 Apr 2008 18:43:05 +0530, santosh <(E-Mail Removed)>
> 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.

Hallvard B Furuseth
Guest
Posts: n/a

 04-27-2008
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

Harald van Dĳk
Guest
Posts: n/a

 04-27-2008
On Sun, 27 Apr 2008 07:24:54 -0500, pete wrote:
> Eric Sosman wrote:
>> http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>>> On Apr 26, 8:21 am, Eric Sosman <(E-Mail Removed)> wrote:
>>>>
>>>> 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

Harald van Dĳk
Guest
Posts: n/a

 04-27-2008
On Sun, 27 Apr 2008 14:33:32 +0200, Harald van Dĳk wrote:
> On Sun, 27 Apr 2008 07:24:54 -0500, pete wrote:
>> Eric Sosman wrote:
>>> (E-Mail Removed) wrote:
>>>> On Apr 26, 8:21 am, Eric Sosman <(E-Mail Removed)> wrote:
>>>>>
>>>>> 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.

David Thompson
Guest
Posts: n/a

 05-05-2008
On Sat, 26 Apr 2008 13:31:20 +0000, Richard Heathfield
<(E-Mail Removed)> wrote:

> 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]

<Python> No 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

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post grocery_stocker Python 4 05-02-2009 03:30 PM Jason R. Coombs Python 0 06-13-2008 12:16 AM - Bobb - MCDST 5 12-13-2005 05:14 AM Frankie Montenegro C++ 3 10-14-2005 04:21 PM Kayla Digital Photography 11 07-19-2005 12:48 AM