www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/18/10:32:36

Xref: news2.mv.net comp.os.msdos.djgpp:6121
From: lehmann AT mathematik DOT th-darmstadt DOT de (Alexander Lehmann)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: int main()
Date: 18 Jul 1996 13:11:40 GMT
Organization: Technische Hochschule Darmstadt
Lines: 39
Message-ID: <4sld6c$22hv@rs18.hrz.th-darmstadt.de>
References: <Pine DOT SGI DOT 3 DOT 93 DOT 960718102837 DOT 21991B-100000 AT gibson DOT eee DOT upd DOT edu DOT ph>
NNTP-Posting-Host: fb0410.mathematik.th-darmstadt.de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019