Subject: Re: exit() undefined in bootloader build
To: None <John.P.Darrow@wheaton.edu>
From: Gary Thorpe <gat7634@hotmail.com>
List: tech-kern
Date: 06/01/2002 21:02:24
*If* you attempt to compile a program using a compiler which attempts to be
ANSI-compliant (such as gcc) with all the ansi compliance flags set (-ansi
-pedantic), and you do not have main return int, you will get a compile
error. When compiling this boot loader, is this simply avoided by leaving
out the '-ansi -pedantic'? Is there some special 'self-hosted' flag to pass
to the compiler? If not, then it would seem the code is not ANSI-complaint.
From searching comp.lang.c and other newsgroups here are my conclusions:
1. Since 'exit(int);' and 'return int;' are similar if not equivalent, the
logical thing to do is to declare 'int main(...)' according to the ANSI
standard (how much sense is it to have a 'void func()' return a value?).
2. main() must return int in ansi compliant code for hosted environments.
3. Hosted/self-hosted cannot be determined at compile time (unless gcc has a
flag for this), so 2 must always be true (the compiler must assume the
program is hosted).
4. Since self-hosted code will probably never return (but calling exit()
makes it return!), this technicality may not matter anyway.
5. Since doing 'void main()' is undefined, it may produce bogus code
regardless (what happens when 'void func()' has a line in it saying 'return
0'?). Remember that this has to be sorted out at compile time.
Since it would be easy to write 'int main()' instead of 'void main()' I
wonder why so many people leap to defend leaving it the way it is because
this is still 'correct'. Is the thought of imperfection that unbearable?
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.