public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* What is __main?
@ 2002-08-28  8:12 rob
  2002-08-28  8:39 ` John Love-Jensen
  0 siblings, 1 reply; 3+ messages in thread
From: rob @ 2002-08-28  8:12 UTC (permalink / raw)
  To: gcc-help

I am running a port of gcc under windows, and when I compile code it
outputs code with the symbol "__main" in it - can anyone explain why it
does this, and what the symbol is used for?

Cheers,

Robert

--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: What is __main?
  2002-08-28  8:12 What is __main? rob
@ 2002-08-28  8:39 ` John Love-Jensen
  2002-08-28 11:17   ` Ricardo Anguiano
  0 siblings, 1 reply; 3+ messages in thread
From: John Love-Jensen @ 2002-08-28  8:39 UTC (permalink / raw)
  To: rob, gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: What is __main?
  2002-08-28  8:39 ` John Love-Jensen
@ 2002-08-28 11:17   ` Ricardo Anguiano
  0 siblings, 0 replies; 3+ messages in thread
From: Ricardo Anguiano @ 2002-08-28 11:17 UTC (permalink / raw)
  To: John Love-Jensen; +Cc: rob, gcc-help

John Love-Jensen <eljay@adobe.com> writes:

> Hi Robert,
> 
> Good question.
> 
> The __main() routine is the bootstrap code that eventually calls
> main().  [...]

You may also find information on __main in the GCC internals info
pages:

http://gcc.gnu.org/onlinedocs/gccint/Collect2.html#Collect2

HTH,
-- 
Ricardo Anguiano
CodeSourcery, LLC

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-08-28 18:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-28  8:12 What is __main? rob
2002-08-28  8:39 ` John Love-Jensen
2002-08-28 11:17   ` Ricardo Anguiano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).