From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Mike Laman" To: "GCC" Subject: Re: __main Date: Thu, 29 Aug 2002 22:18:00 -0000 Message-id: <001e01c24fe4$f4b6e580$5aa80844@fed1.sdca.home.com> References: <002f01c24f89$6ad6efa0$0a00000a@zarquin> <20020830044008.A479336@murlibobo.cs.mu.OZ.AU> X-SW-Source: 2002-08/msg01952.html When running a C cross compiler where one does not want a call to "__main()" to be emitted, how can one turn it off? Thanks in advance, Mike ----- Original Message ----- From: "Fergus Henderson" To: "Robert Spanton" Cc: Sent: Thursday, August 29, 2002 11:40 AM Subject: 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: < http://www.cs.mu.oz.au/~fjh > | -- the last words of T. S. Garp.