Topic: Unused named function argument
Author: andrew.gottemoller@debesys.net
Date: Thu, 30 Aug 2012 10:36:40 CST
Raw View
When compiling using gcc with, the below code will compile without any sort of error:
int foo (int)
{
return 5;
}
Can the compilation result differ if I specify a name for the argument?
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?
--
[ 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 ]
Author: James Kuyper <jameskuyper@verizon.net>
Date: Fri, 31 Aug 2012 09:20:17 CST
Raw View
On 08/30/2012 12:36 PM, andrew.gottemoller@debesys.net wrote:
>
> When compiling using gcc with, the below code will compile without any sort of error:
>
>
> int foo (int)
> {
> return 5;
> }
>
>
> Can the compilation result differ if I specify a name for the argument?
>
> 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?
In n1570 (which is very close to C2011) 6.9.1p5 is a constraint applying
to function definitions: "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.
..." The C99 wording was identical.
6.9.1p6 says equivalent things about K&R style function declarations,
which are still allowed.
I could find no comparable wording in the C++ standard, so this may not
be true of C++11.
--
[ 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 ]
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?=<daniel.kruegler@googlemail.com>
Date: Wed, 5 Sep 2012 11:24:01 -0700 (PDT)
Raw View
[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 ]
Author: James Kuyper <jameskuyper@verizon.net>
Date: Thu, 6 Sep 2012 13:04:28 CST
Raw View
On 09/05/2012 02:24 PM, Daniel Kr=FCgler wrote:
> [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?
Presumably , he meant either "compiling using gcc" or "compiling with
gcc", both of which mean pretty much the same thing.
--
[ 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 ]