void main
was never in the standard. He's correct. It never was since it's implementation defined. However, he claims that ISO C states that a required type of int is required for ISO C, which I can only imagine is meant in C99 given the date the article was made since there is no wording supporting this. Responses provided apparently include the standard's provided examples. I claimed that the examples are just that, examples. They shouldn't provide every use case nor do any other examples in the standard do so. |
"Program termination" A return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument. If the main function executes a return that specifies no value, the termination status returned to the host environment is undefined. |
which indicates main will be returning a value, even if that value may be undefined. (Note that in C, returning from functions without returning a value, even though the function promised to return one, was (is?) perfectly legal as long as the return values were not used in the cases where they were not returned -- not having destruction makes that possible. |
The original ANSI C standard (X3.159-1989) was ratified in 1989 and published in 1990. This standard was ratified as an ISO standard (ISO/IEC 9899:1990) later in 1990. There were no technical differences between these publications, although the sections of the ANSI standard were renumbered and became clauses in the ISO standard. This standard, in both its forms, is commonly known as C89, or occasionally as C90, from the dates of ratification. The ANSI standard, but not the ISO standard, also came with a Rationale document.To select this standard in GCC, use one of the options -ansi, -std=c90 or -std=iso9899:1990; to obtain all the diagnostics required by the standard, you should also specify -pedantic (or -pedantic-errors if you want them to be errors rather than warnings). |
gcc -c mainT.c -ansi -pedantic |
mainT.c:1:6: warning: return type of ‘main’ is not ‘int’ [-Wmain] void main() ^ |
Meaning that even in C89, void main was illegal in regards to the standard. |
gcc -ffreestanding -ansi -pedantic test.c |
int main(void) { /* ... */ }
and int main(int argc, char *argv[]) { /* ... */ }
or their equivalent forms.int main(int argc, char *argv[], char *envp[] )
is commonly supported; supporting such a main() does not make an implementation non-conforming. However, the standard does not require that any alternate form of main must be supported.void main()
must be diagnosed and a diagnostic must be issued by a conforming hosted implementation. A particular implementation may silently accept void main()
and the program may either crash or proceed normally, another may issue a warning diagnostic, yet another may treat the program as ill-formed - all three would still be conforming implementations.Some things are considerably harder to implement and provide little benefit overall while others are much easier to implement and provide major benefit. |