4 ms·
I want to say "Static Initialization Order Fiasco!" but that only applies in cross-translation unit scenarios. Were x and y defined in different TUs? It's eith
by neuromanser 3y ago
I want to say "Static Initialization Order Fiasco!" but that only applies in cross-translation unit scenarios. Were x and y defined in different TUs? It's either that or a compiler bug.
https://en.cppreference.com/w/cpp/language/siof https://en.cppreference.com/w/cpp/language/siof
- KMag 3y agoSorry, from the context, you could assume the above is C++. In C89, floating point literals aren't constant expressions, and static initialization order within a compilation unit is only defined for constant expressions. I believe this is also the case for C99, and things get much more fuzzy for me for C standards after C99. As stated in another comment, I got burned by this in 2003 in porting some very large network simulation from Linux on x86 to run on Solaris on my client's $250,000 SunFire V1280. GCC was initializing two const doubles in the file in top-to-bottom order, but Sun Studio was doing the opposite. Switching the file in question to C++ solved the bug, but Sun's C++ compiler generated slower code in this case. So, I changed the static const doubles to #defines to fix the bug.