B
Ben Bacarisse
jacob navia said:This is the definition of a function with an unspecified
number of arguments.
You may have missed it because it is in the "wrong" place, but:
6.7.5.3 Function declarators (including prototypes)
states in paragraph 14:
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.
I do not think so. But I am not a language lawyer.
Is it not an important skill for a compiler writer?
This means that main has no prototype since you did NOT
provide a prototype
Here I am with you.
6.9.1 Function definitions
states in paragraph 7:
The declarator in a function definition specifies the name of the
function being defined and the identifiers of its parameters. If the
declarator includes a parameter type list, the list also specifies
the types of all the parameters; such a declarator also serves as a
function prototype for later calls to the same function in the same
translation unit. If the declarator includes an identifier list,139)
the types of the parameters shall be declared in a following
declaration list. In either case, the type of each parameter is
adjusted as described in 6.7.5.3 for a parameter type list; the
resulting type shall be an object type.
This suggests to me that a function definition with no "parameter tpye
list" (note that int main() has an empty "identifier list" -- no the
same at all) is not a prototype. Given the special execption I quote
above it seems likely that this is a bug in the standard, but there it
is. I think you are right that int main() does not act as a prototype
for subsequent calls.
and main *IS* always called!
Ah, but that is not the meaning of "for later calls to the same
function in the translation unit". You would be right to complain
about:
int main()
{
return main();
}
because the subsequent call has no prototype.
It is an ANSI definition. int main(void) is OK but so are equivalent
forms and they snuck in a phrase that makes int main() equivalent. At
least that is my reading of it.