How should main() be declared?

According to the C standard, there are only two standard, valid ways to portably declare main() in a hosted implementation:

	int main (void)
	int main (int argc, char *argv[])

There are some allowed equivalents to the above declarations, but note that in particular main() must return int. As for the actual values that main() may return, there are only three portably meaningful return values: 0, EXIT_SUCCESS, and EXIT_FAILURE. The former two values indicate success; I prefer EXIT_SUCCESS over 0 for its mnemonic value, but they are equally acceptable. The latter indicates failure. EXIT_SUCCESS and EXIT_FAILURE are macros defined in <stdlib.h>.


Last updated 03 Jan 2004 12:45. Copyright © 2004 Ben Pfaff.
May be freely redistributed, but copyright notice must be retained.