• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Signedness of sizeof()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Signedness of sizeof()
      • From: Andreas Grosam <email@hidden>
    • Re: Signedness of sizeof()
      • From: Clark Cox <email@hidden>
  • Prev by Date: Re: Generating a parseable #include dependency graph from a project?
  • Next by Date: subversion: svn copy WC URL fails
  • Previous by thread: XCode, libs and SNMP
  • Next by thread: Re: Signedness of sizeof()
  • Index(es):
    • Date
    • Thread