[lkml]   [2001]   [Aug]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: [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

    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

    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.


    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 13:01    [W:0.022 / U:3.816 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site