4 ms·
Quote from 6.7.6.3.14 of the C++11 spec (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf):
by rui314 8y ago
Quote from 6.7.6.3.14 of the C++11 spec (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf):
> An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.
So, my interpretation is that the following two function definitions define the same function of the exact same type
void func() {}
void func(void) {}
although the following two function declarations declare two functions of different types
void func();
void func(void);
- deleted 8y ago[deleted]
- kazinator 8y agoThat is of course the C11 (draft) spec, not C++. Interesting find there. The wording is also in the C99 draft; it is not new. It is in fact saying that the empty list in a definition is a special case and does declare that the function takes no parameters. To "specify" here can be understood to mean as inserting information about type into the declaration scope; that which a declaration does. So that's a bit of a bug in GCC there; it should be treating this the same as (void) and therefore diagnosing that way. If not by default, then at least when -pedantic is applied. But nope: $ gcc -Wall -W -std=c11 -pedantic proto.c $
- nezirus 8y agoMy understanding is that, unless you have a function prototype, you will lose type info about the parameters: "The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied." i.e. the most important is the end of that sentence, so GCC behavior should be right.
- kazinator 8y agoNote the: "that is not part of a definition". This is about declarations only.