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

Re: Comparison of promoted ~unsigned


  • Subject: Re: Comparison of promoted ~unsigned
  • From: Alastair Houghton <email@hidden>
  • Date: Tue, 6 Oct 2009 22:40:36 +0100

On 2009-10-06, at 8:52, Jonny Taylor <email@hidden> wrote:

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

On 6 Oct 2009, at 18:56, Markian Hlynka wrote:

I think it's the < operator that's doing the promotion.

No, I think the OP is right; the second warning is wrong, assuming it does indeed warn on that line (I haven't checked). The cast to unsigned short means that the latter comparison was between two unsigned shorts, which shouldn't warn.


The worry, of course, is that the compiler has ignored the cast for some reason and that that's why the warning is being generated.

I think I would be inclined to rewrite the code as

  unsigned short a = 1;
  unsigned short b = ~a;

  if (a < b)
    exit (0);

since I expect that will force the issue.

Kind regards,

Alastair.

--
http://alastairs-place.net




_______________________________________________ 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: Jonny Taylor <email@hidden>
References: 
 >Comparison of promoted ~unsigned (From: Jonny Taylor <email@hidden>)
 >Re: Comparison of promoted ~unsigned (From: Markian Hlynka <email@hidden>)

  • Prev by Date: Re: Comparison of promoted ~unsigned
  • Next by Date: Re: How to work on case-sensitive projects?
  • Previous by thread: Re: Comparison of promoted ~unsigned
  • Next by thread: Re: Comparison of promoted ~unsigned
  • Index(es):
    • Date
    • Thread