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


On 29-Aug-2002, Robert Spanton <rob@xgoat.com> 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 <fjh@cs.mu.oz.au>  |  "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.


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