This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]