1

I have this code:

file1.cpp

int foo()
{
   static bool b = false;

   ... more code ...
}

This file compiles to a shared library, libfoo.so and this library is linked to an application.

My question is, when the application restarts - it gets killed and started by system - the static variables are re-initialized, am I right?

Another words, after each application re-start, at first time running to function foo(), b's value is false.

my_question
  • 3,075
  • 2
  • 27
  • 44
  • 4
    Yes. Upon application termination it's entire memory space is freed so any globals/statics can't persist – SomeWittyUsername Jun 02 '20 at 16:35
  • 1
    @SomeWittyUsername Answers go in the answers section. Not in comments. – Jesper Juhl Jun 02 '20 at 16:43
  • @JesperJuhl I don't feel this qualifies for a full-fledged answer. You're welcome to elaborate and post an answer – SomeWittyUsername Jun 02 '20 at 16:47
  • 1
    @SomeWittyUsername - Short does not mean incomplete or inadequate. [Terse in fact often suggests elegance](https://copyblogger.com/ernest-hemingway-top-5-tips-for-writing-well/). I think others will agree, up-votes will follow. – ryyker Jun 02 '20 at 16:54

0 Answers0