On Nov 15, 2004, at 12:22 PM, Steve Mills wrote:
Because a) DescType is defined as unsigned; b) your enum is implicitly
signed; and c) your enumerators are all negative. They can never be
equal to an unsigned (i.e. always positive) value.
The warning message makes it sound worse than it really is. The actual compiled machine instruction; does it really care about signed/unsigned when doing equality comparisons on 4-byte integers? I don't see why it would when it should just be comparing all 32 bits.
The compiler
absolutely cares about signedness when doing comparisons. It also takes for granted that if you made a certain type signed vs. unsigned, that you care, too. With optimization off, the compiler could possibly generate machine instructions that (as it predicted) will never execute the other branch, because the microprocessor has specific machine instructions for doing signed vs. unsigned compares. With optimization on, it may actually omit the test and branch and all the code in the branch that can never be taken.
Is there a way I've forgotten about or just aren't familiar with to make all the constants in an enum {} be unsigned? They're all defined as 4-char codes, which I thought were naturally unsigned to begin with.