Messages in this thread | | | From | Daniel Phillips <> | Subject | Re: [IDEA+RFC] Possible solution for min()/max() war | Date | Thu, 30 Aug 2001 19:01:25 +0200 |
| |
On August 30, 2001 05:28 am, Linus Torvalds wrote: > 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.
Lets not go into how stupid that is. Yes, things changed between K&R editions 1 and 2, in a misguided attempt to make things less "surprising" the drafters just introduced additional confusion.
> 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.
More than anything, it shows that education is needed, not macro patch-ups. We have exactly the same issues with < and >, should we introduce three-argument macros to replace them?
-- Daniel - 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/
| |