Find The Bug
The part of the conclusion in the green box below for 32 bit linux/GCC (g++) is wrong. A “long long” type is 64 bits wide for that platform combo. If you can read the small and blurry text in the dang thing, can you find the simple logical bug in the five line program that caused the erroneous declaration? And yes, it was the infallible BD00 who made this mess.
Categories: technical
bug, c++, linkedin, programming
My guess would be that you -first- add 1 to the long_rollover_test, and then assign that value to the long_long_test. On a 64 bits system, no problem, but on a 32 bits system it would rollover first, and then assign the negative value to the long_long_test. Though I’m not sure about how assigning values works in C++, I’m more C# myself.
Close. Since “long_rollover_test” is a “long”, the addition of the literal “1” (which is a long too) produces a long type result – which rolls over on machines where longs are 32 bits. If “1LL” was added to “long_rollover_test” instead of “1”, then the compiler would’ve promoted “long_rollover_test” to a “long long” and the addition wouldn’t have rolled over. Thanks.