Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Daniel Krügler<daniel.kruegler@googlemail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Re: Unused named function argument |
| Date | 2012-09-05 11:24 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <k25tpu$atv$1@dont-email.me> (permalink) |
| References | <61b7661d-5cbf-4246-93a2-4ab9dcc6ed12@googlegroups.com> |
[2nd attempt after 4 days]
On 30.08.2012 18:36, andrew.gottemoller@debesys.net wrote:
>
> When compiling using gcc with, the below code will compile without
any sort of error:
What is "compiling using gcc with," supposed to mean?
> int foo (int)
> {
> return 5;
> }
>
> Can the compilation result differ if I specify a name for the argument?
Not in this case. Of-course introducing a parameter name could have an
effect in other cases e.g. via name-hiding. Consider
int bla(){ return 5; }
int foo(int)
{
return bla();
}
Assume now that we introduce the parameter name 'bla' here, this will
make the existing code ill-formed.
> I can't see any way the naming of the parameter would ever make a
difference in the actual compilation result. The question arose because
I noticed when compiling the following C program:
>
>
> // Compile: gcc --std=c99 -c -pedantic -Wall -O3 foo.c
> int foo (int)
> {
> return 5;
> }
>
>
> The error: 'parameter name omitted' is output by the compiler.
>
> Is there any non-obvious significance in the parameter name with
C++11 or C99?
Yes, there is. In C99 (I have no older C standard available for further
reference) we find in 6.9.1 p5:
"If the declarator includes a parameter type list, the declaration of
each parameter shall include an identifier, except for the special case
of a parameter list consisting of a single parameter of type void, in
which case there shall not be an identifier."
In other words: The above function definition is ill-formed in C99, but
not in C++ (Note that for non-defining function declarations this
restriction does not exists).
HTH& Greetings from Bremen,
Daniel Krügler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Next in thread | Find similar
Unused named function argument andrew.gottemoller@debesys.net - 2012-08-30 10:36 -0600
Re: Unused named function argument James Kuyper <jameskuyper@verizon.net> - 2012-08-31 09:20 -0600
Re: Unused named function argument Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-09-05 11:24 -0700
Re: Unused named function argument James Kuyper <jameskuyper@verizon.net> - 2012-09-06 13:04 -0600
csiph-web