gcc (lack of) return type warnings

Tobias Pflug tobias.pflug@exorbyte.com
Wed Feb 14 15:12:00 GMT 2007

Andreas Schwab wrote:
> Tobias Pflug <tobias.pflug@exorbyte.com> writes:
>> This will compile just fine. When compiled with -Wall it will at least
>> bring up a warning about the missing return statement in foo(), nothing
>> about main tho either. Or is there some standard that implicitly declares
>> main to return 0 when there is no explicit return statement?
> If the return value of a function is never used then it is perfectly valid
> to fall through the end of it.  For main, the default action is to return
> 0 since C99.
> Andreas.

Well this might be, but the behavior of gcc does not change depending
on whether or not it is being used.

int foo() {}
int main() { foo(); }

^ No problem here

int foo() {}
int main
{ int test = foo();

^ But this compiles without complaining as well. The result is random 
values for test.

That's not desirable is it ?


More information about the Gcc mailing list