Messages in this thread |  | | | Date | Wed, 29 Aug 2001 20:28:20 -0700 (PDT) | | From | Linus Torvalds <> | | Subject | Re: [IDEA+RFC] Possible solution for min()/max() war |
| |
On Thu, 30 Aug 2001, Daniel Phillips wrote: > > Yes, in the signed/unsigned case the comparison generated is always > unsigned.
Well... No.
If you compare a signed integer with a unsigned char, the char gets promoted to a _signed_ integer, and the comparison is signed. It is NOT a unsigned comparison.
And THIS is one example of why it gets complicated.
The C logic for type expansion is just a tad too easy to get wrong, and the strict type-checking you normally have with well-written ANSI C simply does not exist for integer types. The compiler will silently just do the promotion..
Somebody mentioned -Wsign-compare. Try it with the example above. It won't warn at all, exactly because under C both sides of such a compare have the _same_ sign, even if one is a "unsigned char", and the other is a "signed int".
Try it yourself if you don't believe me.
Please guys. The issue of sign in comparisons are a LOT more complicated than most of you seem to think.
Linus
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
|  |