J
jose luis fernandez diaz
Hi,
I am reading Stroustrup's book 'C++ Programming Language'. In the
10.4.9 section (Nonlocal Store) he says:
"A variable defined outside any function (that is global, namespace,
and class static variables) is initializated (constructed) before main
is invoked . . ."
.. . .
"No implementation-independent guarantees are made about the order of
construction of nonlocal objects in different complication units . .
.."
So this is wrong:
// foo1.C
int x = 1;
// foo2.C
extern int x;
int y = x;
So when I want initializated a global or class static variable with
other global variable is convenient do it after the main is invoked.
How can I sure that a global variable is initializated before the main
is invoked when I am working with different compilation units?
Thaks,
Jose Luis.
I am reading Stroustrup's book 'C++ Programming Language'. In the
10.4.9 section (Nonlocal Store) he says:
"A variable defined outside any function (that is global, namespace,
and class static variables) is initializated (constructed) before main
is invoked . . ."
.. . .
"No implementation-independent guarantees are made about the order of
construction of nonlocal objects in different complication units . .
.."
So this is wrong:
// foo1.C
int x = 1;
// foo2.C
extern int x;
int y = x;
So when I want initializated a global or class static variable with
other global variable is convenient do it after the main is invoked.
How can I sure that a global variable is initializated before the main
is invoked when I am working with different compilation units?
Thaks,
Jose Luis.