Mail Archives: djgpp/1996/07/03/18:45:25
There have been plenty of opinions offered here, but has anyone actually
consulted the ANSI spec? The relevant section is 5.1.2.2.1, where it is
explained that "the implementation defines no prototype for this function
[main]..." The ANSI document goes on to give an example where "main" can
be defined
int main(void) { /*...*/ }
and specifications for the arguments argc and argv *if they are defined*.
(Since they are local to main, they don't even have to be named argc and
argv, but only an IOCCC entry would name them anything else.) Since the
prototype is not defined in the ANSI spec, one is free to declare it
void main()
or even
main()
wherupon it defaults to type "int".
In section 5.1.2.2.3, the ANSI document states "If the main function
executes a return that specifies no value, the termination status
returned to the host environment is undefined." It is therefore implied
that "void main" is not an error.
The Borland C++ compiler will flag void main() as an error if the -A
(strict ANSI) switch is specified, but this is an error, since, as you
see, the return type of main is *not specified* in the ANSI standard.
Good programming practice is another matter.
-Eric Rudd
- Raw text -