This is the mail archive of the 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: __main

On 29-Aug-2002, Robert Spanton <> 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
> "__main"?

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 <>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

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