Re: Comparison of promoted ~unsigned
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