-1

  • September 26, 2021
  • admin
  • No Comments

(Originally published October 12, 2008)

At my job I spend a fair amount of time porting software. Porting is difficult, and in the product I work on, which is fairly mature, most of the issues I run into are configuration or environmental, and not problems with the code.

It’s interesting to find things in the code that actually need to be changed for a port. I came across this interesting one when porting from 32-bit to a 64-bit compiler in C++. (I believe this syntax is correct, as I’m not in front of the code.)

int value = 0xFFFFFFFF;

The intention was an integer that had all bit fields turned on, which, for a signed value, is equivalent to -1. But when this code is compiled with a 64-bit compiler, the intent is broken. The value is now ’0x00000000FFFFFFFF’, which is no longer equivalent to -1.

The fix:

int value = -1;

Drop Your Comment