This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc (lack of) return type warnings
- From: Tobias Pflug <tobias dot pflug at exorbyte dot com>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 14 Feb 2007 16:11:51 +0100
- Subject: Re: gcc (lack of) return type warnings
- References: <45D319AB.5010209@exorbyte.com> <je4pposrs3.fsf@sykes.suse.de>
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