ordering of constructors

Phil Edwards phil@codesourcery.com
Mon Apr 12 17:13:00 GMT 2004


On Fri, Apr 09, 2004 at 09:18:11PM -0400, Daniel Jacobowitz wrote:
> On Sat, Apr 10, 2004 at 01:34:44AM +0200, Gabriel Dos Reis wrote:
> > 
> > Are you saying GCC never delays dynamic initializations until a point
> > int main()?
> 
> I don't believe it does for any file scope variable, which will be
> initialized before main - or on systems where we can't do that, the
> initializations will be emitted inside main but before the first
> statement of main (? or a wrapper function placed around main?

For modern (read, ELF SysV-ish) systems, it's done by the loader before main.

For the rest, it's done by a generated __main function, and we emit a call to
__main() as the very first thing in main(), before we've analyzed or emitted
anything else in main().  The actual contents of __main are determined at
link time.  The user has no control over this, even if he writes

  int main()
  {
    do_something_to_announce_the_beginning_of_main_but_
     without_using_any_dyn-init'd_variables_that_would_force_their_creation();

our code will still slide in there first.  They will still be created
before any user-visible main() statement.

So, no, we never delay dynamic initialization until after main() begins,
as far as the user can tell.

-- 
Behind everything some further thing is found, forever; thus the tree behind
the bird, stone beneath soil, the sun behind Urth.  Behind our efforts, let
there be found our efforts.
              - Ascian saying, as related by Loyal to the Group of Seventeen



More information about the Gcc mailing list