This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc (lack of) return type warnings


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(); test++; printf("%d\n",test); }

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

That's not desirable is it ?

-Tobi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]