Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:03:06+00:00 2026-05-27T20:03:06+00:00

My question pertains to the order of initialization of global objects. It is discussed

  • 0

My question pertains to the order of initialization of global objects. It is discussed to some extent here: C++: When (and how) are C++ Global Static Constructors Called?

What I would like to know is, how is it guaranteed that some system library objects (can’t think of an example though) are initialized before they are used in application? (I know the solution is to wrap such object in a function, but I want to understand how it is dealt in compilers today)

This is also discussed in the book “linkers and loaders” by John Levine, while talking about .init and .finit sections, but the current state of art is not clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:03:07+00:00Added an answer on May 27, 2026 at 8:03 pm

    An example would be cout.

    The compiler doesn’t really guarantee that those objects are built before they are used. Take this code:

    struct Foo
    {
    
        Foo();
    }foo;
    
    #include <iostream>
    
    Foo::Foo()
    {
        std::cout << "Hello World";
    }
    
    int main() {}
    

    It segfaults because the foo object gets built before cout. When it tries to use cout, bad things happen.

    Basically, all the global objects will get code inserted to construct them which runs before main. Once you are in main you are safe, all objects are built. Before that it depends on the order in which they are defined. That’s why I can break it by including iostream after declaring the foo global.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To all: This question pertains to some MS research I am doing. What I
This question pertains primarily to good design. Suppose I have a controller action like
This question pertains to pretty much all C-like curly bracket programming languages. I'm talking
I'm currently integrating external applications in my app ex SalesForce.com. My question pertains to
Question context: let say that there is some really important row in config/locales/en.yml that
Question is already been asked in title. Here is a code: (function($){ var filter
Question in title pretty much sums it up. I have some resource object defined
Question I'd like the CSS background texture for my content area to begin immediately
This question pertains to MVC (Model-View-Controller). My Model currently updates my View when it
Afternoon all, My question pertains to 2 chained forms, where values from the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.