On Sat, Jun 23, 2012 at 08:10:06AM -0700, Chris Stratton wrote:
> On Jun 23, 9:56?am, Jim Graham <
spooky1...@gmail.com> wrote:
> > Just curious.... ?I see a lot of "void android_main()" in NDK samples.
> > I know that's definitely not legal in standard C
>
> On the contrary, it's perfectly legal standard C.
When did ANSI Standard C start accepting "void main()" ? Granted, it's
been a long time, but I definitely remember that, at least previously,
ANSI C did NOT allow main to be void, and doing so caused undefined
behavior.[1]
> Try it with your favorite non-android C compiler.
Usually, at least back then, compilers ignored it and, if anything,
issued a warning, but then when the program exited, it would still return
a (random) value or 255 (depending on the compiler, the phase of the
moon, the price of tea in China, or whatever else you want to blame it
on). But it ALWAYS returned something, even if you violated ANSI C and
declared main to be void.
I'd check in my book on ANSI C, but it's back from when main ALWAYS
returned an int, and void main was undefined, so it wouldn't indicate
when ANSI re-wrote the C standard.
I did just check, and yes, main still returns an int whether you want it
to or not. I also went ahead and did a quick test, where I declared main
as void. Here's the output:
(15:04) % gcc -Wall test.c -o test
test.c:3: warning: return type of 'main' is not 'int'
(15:05) % ./test
Hello World.zsh: exit 12 ./test
(15:05) %
As you can see, gcc still complains that main is not returning an int,
and when it exits, in this case, main returned 12 (i.e., an int).
Later,
--jim
[1] A common comment on comp.lang.c back then wss that undefined
behavior meant that the program could even cause monkeys to fly
out of your nose.....
--
THE SCORE: ME: 2 CANCER: 0
73 DE N5IAL (/4) | DMR: So fsck was originally called
spook...@gmail.com | something else.
< Running Mac OS X Lion > | Q: What was it called?
ICBM / Hurricane: | DMR: Well, the second letter was different.
30.44406N 86.59909W | -- Dennis M. Ritchie, Usenix, June 1998.