Question on Wording

Discussion in 'C Programming' started by Paulo Jorge de O. C. de Matos, Apr 26, 2008.

  1. 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
     
    Paulo Jorge de O. C. de Matos, Apr 26, 2008
    #1
    1. Advertising

  2. Paulo Jorge de O. C. de Matos

    santosh Guest

    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.
     
    santosh, Apr 26, 2008
    #2
    1. Advertising

  3. Paulo Jorge de O. C. de Matos

    Guest

    On Apr 26, 8:21 am, Eric Sosman <> 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
    > > 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
     
    , Apr 26, 2008
    #3
  4. Eric Sosman <> 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) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Apr 26, 2008
    #4
  5. Paulo Jorge de O. C. de Matos

    santosh Guest

    Jack Klein wrote:

    > On Sat, 26 Apr 2008 18:43:05 +0530, santosh <>
    > 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.
     
    santosh, Apr 27, 2008
    #5
  6. 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
     
    Hallvard B Furuseth, Apr 27, 2008
    #6
  7. On Sun, 27 Apr 2008 07:24:54 -0500, pete wrote:
    > Eric Sosman wrote:
    >> wrote:
    >>> On Apr 26, 8:21 am, Eric Sosman <> 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 Dijk, Apr 27, 2008
    #7
  8. 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:
    >>> wrote:
    >>>> On Apr 26, 8:21 am, Eric Sosman <> 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.
     
    Harald van Dijk, Apr 27, 2008
    #8
  9. On Sat, 26 Apr 2008 13:31:20 +0000, Richard Heathfield
    <> 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
     
    David Thompson, May 5, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frankie Montenegro
    Replies:
    3
    Views:
    521
    Frankie Montenegro
    Oct 14, 2005
  2. Jason R. Coombs
    Replies:
    0
    Views:
    223
    Jason R. Coombs
    Jun 13, 2008
  3. grocery_stocker
    Replies:
    4
    Views:
    253
    grocery_stocker
    May 2, 2009
  4. Ersek, Laszlo

    posting history -- wording of C1X sequencing

    Ersek, Laszlo, Sep 23, 2010, in forum: C Programming
    Replies:
    1
    Views:
    298
    Shao Miller
    Sep 24, 2010
  5. ZMZ
    Replies:
    1
    Views:
    325
    Michael Doubez
    Mar 3, 2011
Loading...

Share This Page