A no-void function definition revisited

A no-void function definition revisited

Post by Andrey Tar » Thu, 17 Apr 2008 05:29:56


Hello

I remember that at different times a had different understanding of what
an empty (no-void) parameter list used in a function definition actually
means. Now, after re-reading the corresponding sections of the standard,
I find myself a bit confused about this.

I remember that at some point someone convinced me that an empty
(no-void) parameter list in a function definition _declares_ that
function as having unspecified parameter list (i.e. equivalent to '()'
in a non-defining declaration, no prototype introduced). This agrees
with GCC compiler accepting this code

void foo() {}

int main() {
foo(42);
return 0;
}

without any diagnostic messages.

However, I see that according to 6.7.5.3/14 in C99 (and similar part of
C89/90) an empty parameter list in function definition _specifies_ that
function has no parameters. The entire 6.7.5.3 is actually about
function _declarations_, so I take that the above "specifies" is
supposed to mean that it _declares_ the function as having no parameters
(i.e. declares the function with prototype, equivalent to '(void)'
declaration). Also, the same wording is used in 6.7.5.3/10, which is
about '(void)' declaration.

So, it definitely appears to me that the latter interpretation is
correct and the former is not. And my version GCC is wrong not to issue
a diagnostic message for the above code. Am I missing something here?

--
Best regards,
Andrey Tarasevich
 
 
 

A no-void function definition revisited

Post by Ivan A. Ko » Sat, 19 Apr 2008 00:58:35


Did you look at DR316? I guess it generally answers your questions.

http://www.yqcomputer.com/

--

 
 
 

A no-void function definition revisited

Post by Andrey Tar » Sat, 19 Apr 2008 02:21:22


Hm... It doesn't seem to have much to do with my questions.

--
Best regards,
Andrey Tarasevich
 
 
 

A no-void function definition revisited

Post by Douglas A. » Sun, 20 Apr 2008 10:12:06


No, there are two contexts:
function definition: Similar to foo(void){...
just a declaration: Parameter types are not specified.

The latter property means that use can use it in declaring a
"polymorphic" function pointer, as you can probably find in some
implementations of HOC-like calculators. Apart from that, it has
no other use that I am aware of, other than in legacy code.


I'm not sure about the diagnostic requirement, but certainly there
is an argument mismatch, and I'd expect a diagnostic since there is
no well-defined meaning. () does not mean a variadic interface.
 
 
 

A no-void function definition revisited

Post by Ivan A. Ko » Mon, 21 Apr 2008 18:12:19


A function declarator with empty parentheses match the form with
optional identifier list while only the form with parameter type list
designate function prototype (6.2.1 #2, 6.7.5.3 #5, 6.9.1 #7).

There are a few other places that state the same more or less clearly
(6.2.7 #3, 6.7.5.3 #15, 6.11.6). The latter says directly that function
declarators with empty parentheses do not designate prototypes.


These wordings in the Standard are correct: both the forms specify that
the function has no parameters, even though only one of them introduce a
prototype.


The diagnostic messages are a matter of use, and not the prototype
definition itself. These discussions about the use (as by Douglas or the
DRs referred) end up with that the Commettee has no interest to clarify
related semantics.

--