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 8410351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:09:02+00:00 2026-06-10T00:09:02+00:00

Running c++ on Ubuntu. in configuration.h file i have this (global): static const string

  • 0

Running c++ on Ubuntu.

in configuration.h file i have this (global):

static const string APP_CONFIG_FILE_NAME = "cfg";

in my configuration.cpp (which is singleton by the way, so load configuration is called by constructor of Configuration) i do this:

void Configuration::loadConfiguration() {
    cout<< "config file name "  << APP_CONFIG_FILE_NAME.data();
        load();
}

The load configuration will be called from another global: (this is the key point for the failure)

Timer t(Configuration::Instance()->timeout);

i see that the cost string is not initialized (empty). If i replace the string with char* its initialized in my expected order.

However on another program the same classes for configuration work, so i dont know the problem.

There is another question but not the same since there its not a global.

  • 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-06-10T00:09:03+00:00Added an answer on June 10, 2026 at 12:09 am

    It gets initialized, of course. However, it is likely being initialized in the order you don’t want/expect it initialized in.

    Specifically, it is probably not constructed by the time you use it because you use it during construction of another global.

    Unfortunately, you don’t have a good way to portably specify initialization order of global data. Initialization order among multiple files is not defined by the standard, although it is likely specified by your toolchain. Consequently, altering the order of compilation or building using another toolchain can result in a different initialization order. Search for “static initialization order fiasco” for more details.

    One way to avoid this issue is to declare your static data in a function:

    const std::string& AppConfigFileName() {
      static const std::string name("cfg");
      return name;
    }
    

    Although…I don’t see why this must be static (the function above allows you to return by value — no need for static). Plus, I don’t see why this could not be a plain C string, since you just treat it as a C string in your config loader.

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

Sidebar

Related Questions

I have a an ubuntu we server running mysql 5.1. Previously I had this
I am running Ubuntu 9.04 and have done about a half hour worth of
I'm running Ubuntu to compile a set of code which requires python 2.4. How
I'm running Ubuntu 11.10 and installed Ruby 1.9 like this: $ sudo apt-get install
I have a server that is running Ubuntu Linux Server Edition. I once had
I currently have a CodeIgniter web app running on Ubuntu with nginx. I just
I have an Ubuntu 10.04 server, running PHP 5.3.2 and I have these lines
On an ubuntu server, I have a drupal site which uses nginx+fastcgi as webserver
I have two GeoServers running in the same machine Ubuntu Server 9.04. GeoServer V2.0.1
I am running ubuntu 10.10, and have rabbitvcs & svn installed, I have created

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.