Weird NSNumber allocation expression

63 Views Asked by At

Consider the following NSNumber instances:

NSNumber *b1 = @((long)(-61));
NSNumber *b2 = @((long)(-62));

NSLog(@"%@", b1);
NSLog(@"%@", b2);

The “Variables View” within the “Debug Area” shows curious values:

enter image description here

Does someone has any idea about this debugger infomation?

1

There are 1 best solutions below

0
Rob On

0xffffffffffffffc3 is the hex representation of -61.
0x00ffffffffffffc3 is the hex representation of 72057594037927875.

The “Variables View” within the “Debug Area” simply has troubles correctly representing negative long values of a NSNumber.

enter image description here

What’s ironic is that if you use an unsigned long for the underlying value for the NSNumber (see value4/b4 in above screen snapshot), the variables view will now show it as -61.

But, this is just a bug in the display of the NSNumber instances in the “Variables View”. The actual NSNumber values are fine.