Mail Archives: djgpp/1996/07/18/10:32:36
Orlando Andico (orly AT gibson DOT eee DOT upd DOT edu DOT ph) wrote:
: On Tue, 16 Jul 1996, Nissim Chudnoff wrote:
: > A while ago, there was a conversation about 'void main()' vs. 'int main()'
: > and I wondered if:
: >
: > void main()
: > {
: > exit(1);
: > }
: >
: > Is the same as
: >
: > int main()
: > {
: > return(1);
: > }
: No it's not. The first method (at least, when I tested it under Linux)
: would return a random, nonzero (but small magnitude) positive integer,
: i.e. 2. This is normally used to signal an error condition so it's a bad
: idea to declare void main().
Actually, it should be, return x from main is the same as exit(x),
most startup code simply calls main with something like
exit(main(xxx)) (e.g. the djgpp startup code in /src/libc/crt0/crt1.c).
There may apear a compiler error if a prototype for main is defined,
but it usually isn't since main can be either (void) or (int, char *[])
bye, Alexander
--
Alexander Lehmann, | "On the Internet,
alex AT hal DOT rhein-main DOT de (plain, MIME, NeXT) | nobody knows
lehmann AT mathematik DOT th-darmstadt DOT de (plain) | you're a dog."
!!CHANGED!! <URL:http://www.mathematik.th-darmstadt.de/~lehmann/>
- Raw text -