• 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
Re: Signedness of sizeof()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Signedness of sizeof()


  • Subject: Re: Signedness of sizeof()
  • From: Clark Cox <email@hidden>
  • Date: Tue, 16 Mar 2010 17:28:28 -0700

On Tue, Mar 16, 2010 at 4:14 PM, Hamish Allan <email@hidden> wrote:
> 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:

The sizeof operator always evaluates to a value of type (size_t),
which is guaranteed to be an unsigned type.

>
> Evidently the library author is using an architecture in which the
> comparison is made signed.

There is no such thing as a C architecture where sizeof returns a
signed value. The only situation in which I can imagine this happening
is on a platform where (sizeof(int) > sizeof(size_t)), which would be
a very odd platform indeed.

> 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?

No, I don't believe that there is anything that you can do short of
casting the result of sizeof to a signed type.

--
Clark S. Cox III
email@hidden
 _______________________________________________
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: Hamish Allan <email@hidden>
References: 
 >Signedness of sizeof() (From: Hamish Allan <email@hidden>)

  • Prev by Date: subversion: svn copy WC URL fails
  • Next by Date: Re: Signedness of sizeof()
  • Previous by thread: Signedness of sizeof()
  • Next by thread: Re: Signedness of sizeof()
  • Index(es):
    • Date
    • Thread