views:

248

answers:

1

I'd like to view the value of an NSUInteger at any given time. I assign the value below:

NSUInteger test = -1;

Then try to view it in the debugger:

(gdb) po test
Cannot access memory at address 0xffffffff
(gdb) p test
$1 = 4294967295
Current language:  auto; currently objective-c

Far as I know, it is a value type. Where is -1?

+13  A: 

You're using an NSUInteger, which is unsigned. As such, any negative values assigned will actually be interpreted very large positive values.

You want to use NSInteger which is signed (and therefore can be both positive and negative values). You should then be able to do (gdb) p test to see the value.

Matt Ball
It's also not a pointer to an object, which is what po expects to be given.
Azeem.Butt
Thanks. How can I compare an NSInteger value to a NSUInteger value?
4thSpace
If you know for certain that they are within the overlap range, you can cast NSUInteger to NSInteger in order to compare them. But before putting in a typecast, always carefully consider if the numbers will *always* be in an appropriate range.
Rob Napier
The single line you give is pretty much totally a contradiction. You say you want an unsigned number, then right away you give the number a negative sign.Why not just make the values you are using NSInteger?
Kendall Helmstetter Gelner