This is the mail archive of the
mailing list for the GCC project.
- From: Fergus Henderson <fjh at cs dot mu dot OZ dot AU>
- To: Robert Spanton <rob at xgoat dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 30 Aug 2002 04:40:08 +1000
- Subject: Re: __main
- References: <002f01c24f89$6ad6efa0$0a00000a@zarquin>
On 29-Aug-2002, Robert Spanton <firstname.lastname@example.org> wrote:
> Why is it that when i compile the following code (using the -S switch) under
> windows, GCC outputs an assembly file containing the symbol "__main" (two
> underscores) AND the symbol "_main" (one underscore) - whereas when i
> compile it under unix or bsd, it only contains the symbol "_main" (one
> underscore). Why do the unix and bsd versions not output the symbol
On some systems, gcc inserts a call to __main() at the start of the
code that it generates for main(). __main() is called to execute
initialization code, in particular constructors for C++ objects with
global or namespace scope.
On systems which use the ELF object file format, there are special
sections in the object file for registering initialization code, and
gcc will use these. The program loader (and/or the C runtime start-up
code) will then ensure that the initialization code gets run, perhaps
even before main() is entered, so there's no need for gcc to call __main().
Fergus Henderson <email@example.com> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.