Re: Incorrect warning
Re: Incorrect warning
- Subject: Re: Incorrect warning
- From: Bryan Pietrzak <email@hidden>
- Date: Tue, 16 Nov 2004 09:49:37 -0600
On Nov 16, 2004, at 9:21 AM, Steve Mills wrote:
You mean there's actually an equality operator that compares 32 bits
when the data is signed and another equality operator that compares
the *same* 32 bits when the data is unsigned? How completely odd.
You're joking right?
UInt32 a = 0xFFFFFFFF;
SInt32 b = -1;
Aren't these two values very different even though they have the same
bit representation?
Nope, enums are by default ints, which are by definition signed.
I suppose I could turn the enums back into const's, which is how they
started life many years ago, but then had to be changed to an enum
when we started the cross-platform thang. Oh man.
Yeah, enums in C++ are just not handled as nicely as they should be by
the standard.
Since C++ doesn't allow you to declare the type of an enumeration,
your
two choices are to a) don't use -Wsign-compare or b) explicitly cast
your enumerals to (DescType) in your comparisons.
Arg. I like it a lot better when it just works in CodeWarrior. I like
having the warning on in Xcode for *times when it really matters*, but
for comparing 32-bit integer equality it really shouldn't care about
signs.
What's interesting is this bit of code completely fails my expectations:
UInt32 a = 0xFFFFFFFF;
SInt32 b = -1;
if (a == b)
{
SysBeep(1);
}
In both XCode and CodeWarrior the SysBeep is executed. In this
situation, even though a and b are bitwise equal, they do not represent
the same value and I would not have expected the equality test to
succeed.
Bryan
_______________________________________________
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