Apparently, in at least C++, the evaluation order of static const members is undefined. Someone get me Bjarne Stroustrup's head, right now.
-
-
Vastauksena käyttäjälle @TheMogMiner
Correct. Static member initializers need to be self-contained because the construction/assignment code is run in an unspecified order.
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @KinkTodd
Well just fuck my entire life. I've written 500+ UI widgets for this game on the assumption that it isn't, because MSVC is pretty good at initializing them in instantiation order, lulling me into a false sense of security.
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @TheMogMiner
Basically, you should assume that every static member initializer works like a global variable constructor, because that's what they really are (global variables that happen to be namespaced within a class or struct). Global variables also have undefined initialization order.
1 vastaus 0 uudelleentwiittausta 1 tykkäys -
Vastauksena käyttäjille @KinkTodd ja @TheMogMiner
This is different from something like Java, where whether or not a class static initializer is run depends on whether the class is fully initialized for use. C++ doesn't have that kind of tracking concept of "what globals did I run so far?" to make that topologically consistent.
1 vastaus 0 uudelleentwiittausta 1 tykkäys -
Vastauksena käyttäjille @KinkTodd ja @TheMogMiner
Because of this, in C++, it's usually considered better not to use statics/globals for holding anything more than simple values.
1 vastaus 0 uudelleentwiittausta 1 tykkäys -
Vastauksena käyttäjille @KinkTodd ja @TheMogMiner
(Apologies for the braindump, I was part of the C++98 review committees, so it all randomly oozes out sometimes. And yes, I think the lack of consistency here is a big failing.)
1 vastaus 0 uudelleentwiittausta 2 tykkäystä -
Vastauksena käyttäjille @KinkTodd ja @TheMogMiner
Oh... One common workaround is to create a struct used by a single global variable containing all the globals that need consistent initialization order (in Java parlance, a singleton), because normal class/struct members have defined order. struct { // stuff here } globals;
2 vastausta 0 uudelleentwiittausta 0 tykkäystä
No-go on that one, my man. Due to various engine constraints which I can't/won't get into here, going that route would more or less double our UI system's static memory overhead.
Current plan is to just bite the bullet and change all the static consts to #define-s.
-
-
Vastauksena käyttäjälle @TheMogMiner
Ah if they really are all consts, and simple values at that, yes you're better off letting the preprocessor do it. I'm sorry you had to find out the hard way.
1 vastaus 0 uudelleentwiittausta 1 tykkäys -
Uusi keskustelu -
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.