• 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
Comparison of promoted ~unsigned
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Comparison of promoted ~unsigned


  • Subject: Comparison of promoted ~unsigned
  • From: Jonny Taylor <email@hidden>
  • Date: Tue, 6 Oct 2009 15:52:38 +0100

I am getting some odd warnings with gcc under xcode, and I'm not sure whether this is the compiler being over-zealous or whether it is trying to tell me about a subtle issue I do not appreciate.

The following code generates two warnings:
unsigned short a = 1;
if (a < ~a)
exit(0);
if (a < (unsigned short)(~a))
exit(0);

BOTH "if" tests produce the warning:
warning: comparison of promoted ~unsigned with unsigned

It seems to me that the second test is free from any issues. Yes, I have inverted an unsigned short, which has involved an implicit promotion to int, but I have then cast it back to unsigned short. As far as I can see, that code will work exactly as I would expect. Is there a problem I am not seeing, or is the compiler warning incorrect in this case?

Thanks for any advice.
Jonny


 _______________________________________________
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: Comparison of promoted ~unsigned
      • From: Chris Suter <email@hidden>
    • Re: Comparison of promoted ~unsigned
      • From: Markian Hlynka <email@hidden>
  • Prev by Date: Re: Xcode 3.2 and NSTextField exceptions
  • Next by Date: No Carbon project template after updating OS + SDK
  • Previous by thread: Re: Xcode 3.2 and NSTextField exceptions
  • Next by thread: Re: Comparison of promoted ~unsigned
  • Index(es):
    • Date
    • Thread