This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: What is __main?
- From: John Love-Jensen <eljay at adobe dot com>
- To: <rob at xgoat dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Wed, 28 Aug 2002 10:36:03 -0500
- Subject: Re: What is __main?
Hi Robert,
Good question.
The __main() routine is the bootstrap code that eventually calls main().
It's responsible for initializing your globals, converting the command line
parameters into an array for main() to digest, setting up your
stdin/stdout/stderr FILE* and cin/cout/cerr streams, calling exit with your
main()'s return code, exception handling framework seeding, and other
infrastructure overhead.
The __main() routine is part of the crtXX.YY where XX is usually a 0, 1, 2,
i, n, etcetera, and XX is either a .a, .o, .asm, .c, or whatever. The 'crt'
stands for "C Run Time".
If you don't care about many of the C/C++ standard infrastructure services,
it is possible to write your own crt bootstrap. For example, let's say you
don't care about printf(), and do all your output via write() ... then you
can get by without having the stdin/stdout/stderr FILE* setup for you to
their appropriate fd (file descriptor number).
Hopefully, this explanation is a little better than my usual one, "I'd
explain it to you, but your head would explode." :-)
Sincerely,
--Eljay