user361459
user361459

Reputation: 31

static local variable and static local object initialization

In VC++2008 there is a serious difference in initialization of static local variable and static local object. Static local variable is initialized before main() and its definition statement within the function is skipped. Static local object is initialized by 0 value before main() and its definition statement within the function is executed only once . Constructor is started and object is initialized by appropiate value. All that can be seen in Debug mode. Does this solution correspond to the existing C++ Standard?

Upvotes: 0

Views: 1007

Answers (1)

Vitor Py
Vitor Py

Reputation: 5180

From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf :

Every object of static storage duration shall be zero-initialized at program startup before any other initialization takes place. [ Note: in some cases, additional initialization is done later. —end note ]

Upvotes: 1

Related Questions