Home > technical > Find The Bug

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 Tags: , , ,
  1. May 30, 2012 at 4:50 am

    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.

    • May 30, 2012 at 6:06 am

      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.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: