Quantcast
Channel: Embarcadero Community - Embarcadero Community
Viewing all articles
Browse latest Browse all 3212

Issues comparing unsigned long's in RAD studio 2009

$
0
0

My office is using RAD Studio 2009 for some legacy support on products, however we recently came across the following behaviour and would like to know if anyone has seen this, and knows the cause.

When comparing a pair of unsigned long's we end up getting results where only the least significant 2 bytes are used for the comparison.

A simplified example:

unsigned long Val1 = 0xDC00;
unsigned long Val2 = 0x5A550;

if(Val1 > Val2)
{
//Something horribly wrong
printf("things are bad- Val1:%x > Val2:%x", Val1, Val2);
}

In our code the above scenario is resulting in "something horribly wrong"

I have managed to isolate the issue by changing Val1 to 0xA551 and it still fails, yet 0xA549 will pass. This says that the greater than operator is only checking the lowest order 2 bytes of the unsigned long. However it always prints the correct values in the printf.

The code is running on a Windows XP 32 bit machine, and the sample is a simplified example of the issue, but it captures the behaviour we are seeing.


Viewing all articles
Browse latest Browse all 3212

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>