eq mail said:
Yes it does, at least twice (see examples on pages 91 and 135).
The example on page 91 is in section 6.5.3.4 paragraph 8. The example
on page 135 is in section 6.7.6.3 paragraph 20. Every PDF reader I've
used makes it *much* easier to find things by section number than by
page number (all the page numbers in N1570 are off by 18).
But yes, you're right, N1570 does mention `int main()` (but never
in normative text). Either I didn't know that or I had forgotten it.
Thanks for pointing it out.
It presents two definitions of main that must be supported
by all hosted implementations:
int main(void) { /* ... */ }
int main(int argc, char *argv[]) { /* ... */ }
"or equivalent; or in some other implementation-defined manner."
(C99 and C90 are essentially the same.)
Although it lists the former as an example of the first possible
scenario, I think more important is the actual description, which
reads:
It [main] shall be defined with a return type of int and with
no parameters.
I don't think that either the description or the code is, or should be,
more important than the other. They're both normative and they should
be consistent. The two definitions of `main` could easily have been
marked as examples; they aren't.
The description of the two-parameter form:
or with two parameters (referred to here as argc and argv, though
any names may be used, as they are local to the function in which
they are declared):
is incomplete, since it says nothing about the types of those two
parameters; we need the actual code:
int main(int argc, char *argv[]) { /* ... */ }
to know that they're of type `int` and `char**`.
Similarly, I'd say that the description of the zero parameter form:
... and with no parameters:
is incomplete, and requires the code:
int main(void) { /* ... */ }
to specify just *how* it's defined with no parameters.
Which the following *will* do (while possibly failing to provide a
prototype for itself):
int main() { }
You can safely define main in a way that's "equivalent" to one of
the two forms given, both of which are presented by a combination
of English text and C code. Variations such as using a typedef for
int rather than int, or using different names for argc and argv,
or writing `char **argv` rather than `char *argv[]`, clearly provide
equivalent definitions. It's far less clear that `int main() { }`
does so.
The examples you cite do strongly imply that `int main(){}` was
*intended* to be a valid definition, as does the observation that
making it invalid would have broken pre-ANSI code, something the
C89 committee was generally careful to avoid. My argument is that
the wording of the standard does not accurately reflect this intent.
I'ts plausible that the committee meant for us to assume that `int
main(void){}` and `int main(){}` are "equivalent". They certainly are
equivalent *in some ways*. My reading is that they are *not* entirely
equivalent, and their partial equivalence is not enough to say that
they're "equivalent". This at least needs to be made clearer.
(Dropping old-style function declarations and definitions, as the
standard has been threatening to do since 1989, would neatly resolve
this.)