Initialization of global variables

349 views
Skip to first unread message

Gabriel Dos Reis

unread,
Jun 18, 2014, 5:34:42 AM6/18/14
to mod...@isocpp.org, c++st...@accu.org
Hi,

The reference to the standard text I was looking for earlier in the morning is 3.6.2/3. It has the following illustration (in the same translation unit):

inline double fd() { return 1.0; }
extern double d1;
double d2 = d1; // unspecified:
// may be statically initialized to 0.0 or
// dynamically initialized to 0.0 if d1 is
// dynamically initialized, or 1.0 otherwise
double d1 = fd(); // may be initialized statically or dynamically to 1.0

-- Gaby

Gabriel Dos Reis

unread,
Jun 18, 2014, 7:43:18 AM6/18/14
to c++st...@accu.org, mod...@isocpp.org
| -----Original Message-----
| From: David Vandevoorde [mailto:dav...@edg.com]
| Sent: Wednesday, June 18, 2014 4:33 AM
| To: c++st...@accu.org
| Cc: mod...@isocpp.org
| Subject: [c++std-ext-14932] Re: Initialization of global variables
|
| Sure, but that's really up to the TU (or module) writer. I think it's still highly
| desirable to provide whatever ordering guarantees across library imports that
| we can, and modules provide a fairly intuitive model for that.

OK, but that is different from a claim that we provide a reliable initialization order for global variables -- which is going to be further simplified by real programmers out there, only to be bitten in unsuspected way.

Modules may provide us a way to jump-start that process, but by themselves they don't solve the problem since the it is still there when only a single translation unit is of interest. Then we get the moral equivalent of

-- Gaby


|
| Daveed
Reply all
Reply to author
Forward
0 new messages