Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Jun 1997 07:47:40 +0300
From:      Anatoly Vorobey <mellon@pobox.com>
To:        hackers@freebsd.org
Subject:   Re: Borland 16bit bcc vs cc/gcc (float)
Message-ID:  <19970601074740.37058@techunix.technion.ac.il>
References:  <1.5.4.32.19970531220152.008b46f0@mindspring.com> <Pine.BSF.3.95q.970531190322.1359C-100000@aak.anchorage.net>

next in thread | previous in thread | raw e-mail | index | archive | help
You, Steve Howe, wrote on Sat, May 31, 1997 at 07:10:53PM -0800:

> further, from what i gather, it's good to call exit() on a 
> real OS when you finish a program in case there a hidden/extraneous
> clean-up functions that need to be completed.  

exit() will get called anyway. When you return from main(), you
return to startup code of libc, which will usually call exit().
In some C libs, you actually lose not just main()'s destructors,
as the code in startup function might perform some cleaing up
_before_ calling exit(), although I haven't seen this behaviour
on sane systems/libs.

> and since exit doesn't
> return to main, any return in main is a waste of code.  it might also give
> someone the wrong idea that main actually does return something.

But of course it does. The return value of main() is passed as the
arg to exit() and then to the parent process.

> > In fact, I've observed C++ code that never calls the destructors if you
> > exit() of out a program.
> > 
> > This is one of my favorite rants. I gave a friend of mine the 15 minute
> > explanation of why void main() is wrong, and he told his instructor. She
> > placed him out of her class and into the next one up. 
> 
> i'm just saying it's not an absolute.

Ah, but what is an absolute? ;)

A friend of mine used to despise main(). He said it was too common and
wasn't creative enough. So he hacked libc to link to moose() instead
of main() and his programs didn't have main() in them, which drove
crazy everyone who tried to read the code. After I pointed out
to him that his solution was a moral equivalent of #define moose main,
he abandoned libc altogether, passing moose() as entry point
directly by using an ld option, and went through a short period
of using raw syscalls for i/o...

-- 
Anatoly Vorobey,
mellon@pobox.com http://pobox.com/~mellon/
"Angels can fly because they take themselves lightly" - G.K.Chesterton



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970601074740.37058>