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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:06:58+00:00 2026-06-01T20:06:58+00:00

These are two questions about static locals that have always bothered me and I

  • 0

These are two questions about static locals that have always bothered me and I haven’t found a definitive answer to:

Question 1:

 struct Test
 {
  static inline const char* name()
  {
     static const char* nameValue = "Name of Test";
     return nameValue;
  }
};

Since the method is inline, there should be a copy of this method in each compilation unit that calls it. But, there must be only one instance of the local static variable nameValue (correct me if I am wrong). How is this achieved? We have many instances of a function generated, but all of them refer to the same static local. Does the compiler maintain a global table of static locals associated with each function by name?

Question 2:

 struct Init
 {
   Init() {printf("init created\n");}
  ~Init() {printf("init destroyed\n");}
 };

 struct Test
 {
   static void func()
   {
       static Init init;
   }
 };

The static local Init object is constructed only once, on the first call of func(). How does the compiler know when is the first call to func()? Does it maintain a flag at runtime, whether this is the first call of this func?

  • 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-01T20:06:58+00:00Added an answer on June 1, 2026 at 8:06 pm

    These are really two unrelated questions.

    For the first, there are various solutions. Perhaps the most frequent
    are something called weak symbols. Roughly speaking, the compiler
    generates an instance under a specific name in every object file that
    uses the function, and the linker throws out the duplicates, and only
    keeps one in the final program.

    For the second, the usual solution is to generate a boolean variable
    associated with the object, and tests this when the object comes into
    scope.

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

Sidebar

Related Questions

I have two noobish questions about Flash, Actionscript, Flex etc. 1) With these technologies
I have two questions about static + const members and static classes. One: Why
Here is the question: write a method that swaps two variables. These two variables
So .... There are obviously many questions that all have been asked about Singletons,
This may sound like noobish question but I have tried researching these two classes
I have two questions. The first is about updating the UI, the second is
There are two questions to this: How can I best spread the word about
Actually I have two questions. (1) Is there any reduction in processing power or
The question has two sides. We host a lot of static files for public
my question is about communicating two directions from one class to its child. I

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.