T
Taras_96
Hi all,
A question about initialisation orders of global/namespace/class
static objects.
In "the c++ programming language", Bjarne states that:
page 217
"In principle, a variable defined outside any function (that is,
global, namespace, and class s t a t i c
variables) is initialized before m a i n () is invoked. Such nonlocal
variables in a translation unit are
initialized in their declaration order (§10.4.9). If such a variable
has no explicit initializer, it is by
default initialized to the default for its type (§10.4.2). The default
initializer value for builtin
types and enumerations is 0 . For example:"
But 10.4.9 yields:
"Constructors for nonlocal objects in a translation unit are executed
in the order their definitions occur."
So are nonlocal objects initialized in the order in which they were
declared, or defined? These two statements seem to disagree, and I
couldn't find anything in the errata for the book.
I couldn't find an answer in the Standard:
The standard states that zero-initialisation is done before dynamic
initialisation of nonlocal objects (with a couple of exceptions with
namespace and local statics) - Stmt.dcl/4
However, I couldn't find anything about the initialisation order
(static or dynamic) of nonlocal objects
A question about initialisation orders of global/namespace/class
static objects.
In "the c++ programming language", Bjarne states that:
page 217
"In principle, a variable defined outside any function (that is,
global, namespace, and class s t a t i c
variables) is initialized before m a i n () is invoked. Such nonlocal
variables in a translation unit are
initialized in their declaration order (§10.4.9). If such a variable
has no explicit initializer, it is by
default initialized to the default for its type (§10.4.2). The default
initializer value for builtin
types and enumerations is 0 . For example:"
But 10.4.9 yields:
"Constructors for nonlocal objects in a translation unit are executed
in the order their definitions occur."
So are nonlocal objects initialized in the order in which they were
declared, or defined? These two statements seem to disagree, and I
couldn't find anything in the errata for the book.
I couldn't find an answer in the Standard:
The standard states that zero-initialisation is done before dynamic
initialisation of nonlocal objects (with a couple of exceptions with
namespace and local statics) - Stmt.dcl/4
However, I couldn't find anything about the initialisation order
(static or dynamic) of nonlocal objects