Does this code produce Undefined Behavior or it is merely Unspecified Behavior?-Collection of common programming errors
3.6.2/1 says that “Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place”.
So you’re right, they aren’t default-initialized. But they are zero-initialized, which in fact for int
is the same thing. For a class type it’s not necessarily the same thing.
That said, I’m not promising the behavior here is merely that the order of initialization is unspecified, and hence that one variable ends up as 10 and the other 20, but unspecified which is which. It might be undefined on some other grounds, but I can’t think of any.
Originally posted 2013-11-09 23:00:58.