I have some C programs without any explicit return from main, like this:
int main(int argc, char *argv[])
{
// blah blah
}
If I compile them with GCC 4.6.3 and the following options:
gcc file.c -Wall -Wextra
Programs does not return 0 and give me problems, but the standard (and a lot of other answers on SO) says:
If the return type of the main function is a type compatible with int, 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;[10] reaching the } that terminates the main function returns a value of 0. If the return type is not compatible with int, the termination status returned to the host environment is unspecified.
[10] In accordance with 6.2.4, the lifetimes of objects with automatic storage duration declared in main will have ended in the former case, even where they would not have in the latter.
My programs return different values, 160, 15, 14... garbage?
Am I missing something? Is this a GCC bug? Can't find anything in the GCC online doc. Is GCC still referring to some old C standard (pre-C99) where this could be not specified?
return 0;
to the end ofmain
. It's harmless in C99 mode. – Keith Thompson Oct 8 '13 at 15:19