Article View: comp.std.c
Article #256Re: declaration query
From: david.f.prosser
Date: Tue, 20 Jun 1989 13:34
Date: Tue, 20 Jun 1989 13:34
66 lines
2674 bytes
2674 bytes
In article <14587@watdragon.waterloo.edu> afscian@violet.waterloo.edu (Anthony Scian) writes:
>This question arose from comp.lang.c:
>
>Is this legal (ANSI)?
>int foo( int, int y ) { ... } (1)
No, but it would have been nice if it were valid, in my opinion.
>
>I think this should be legal:
>int foo( int, int y );
Yes, it is valid.
>
>and combined with this:
>int foo( int x, int ) {return(x+y);}
>
>COULD be equivalent to:
>int foo( int x, int y ) {return(x+y);}
No. The scope of prototype parameters in a declaration ends at the
close paren.
>
>The grammar allows this but it is not clear to me what (1) means
>in isolation.
Nothing, since it is invalid. An (obvious, at least to me) interpretation
is to have an int parameter whose value is not accessible in the function.
It would be a more precise (and linguistic) method of noting that a
parameter which is needed for other reasons is unused in a function. One
example is while a program is being developed: the stub functions could
be implemented without drawing comments about unused parameters. Another
is when a number of functions are called indirectly. All these functions
must have identical interfaces for portability, but some of the functions
may well not need the value of certain parameters.
>Can identifiers in prototypes be different than the identifiers
>in the function definition?
Yes, since the scope of the names are completely disjoint.
>What about?
>int test( int, int z );
>int test( int x, int y ) {return(x+y);}
Valid.
>
>Should the compiler keep the identifiers and override them when
>the function is defined (declared)?
No. I see no benefits gained by producing warning messages about
differently named parameters between a declaration (probably in a
header file) and the definition. In fact, the only use for naming
parameters in a declaration is to provide a little documentation
that might help to distinguish between the parameters:
div_t div(int numerator, int denominator);
>
>//// Anthony Scian afscian@violet.uwaterloo.ca afscian@violet.waterloo.edu ////
>"I can't believe the news today, I can't close my eyes and make it go away" -U2
Dave Prosser ...not an official X3J11 answer...
Technical Details
Message-ID:
<854@cbnewsl.ATT.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!att!cbnewsl!dfpReferences:
<14587@watdragon.waterloo.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!att!cbnewsl!dfp From: dfp@cbnewsl.ATT.COM (david.f.prosser) Newsgroups: comp.std.c Subject: Re: declaration query Message-ID: <854@cbnewsl.ATT.COM> Date: 20 Jun 89 13:34:13 GMT References: <14587@watdragon.waterloo.edu> Reply-To: dfp@cbnewsl.ATT.COM (david.f.prosser) Distribution: comp Organization: AT&T Bell Laboratories Lines: 66