Signedness of sizeof()
Signedness of sizeof()
- Subject: Signedness of sizeof()
- From: Hamish Allan <email@hidden>
- Date: Tue, 16 Mar 2010 23:14:42 +0000
I am using a piece of library code in which an int is compared with
the result of a sizeof(). The comparison appears to be unsigned, i.e.
the int is coerced into an unsigned int. To illustrate:
int a = -1;
if (a >= sizeof(a))
{
NSLog(@"%d >= %d", a, sizeof(a));
NSLog(@"%u >= %u", a, sizeof(a));
}
outputs:
2010-03-16 23:09:41.666 SizeofTest[17587:a0f] -1 >= 4
2010-03-16 23:09:41.672 SizeofTest[17587:a0f] 4294967295 >= 4
Evidently the library author is using an architecture in which the
comparison is made signed. Rather than change his code to cast the
result of every sizeof() to an int before comparing, is there anything
simpler I can do, e.g. set a compiler flag or #define?
Thanks,
Hamish
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden