[lkml]   [2001]   [Aug]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [IDEA+RFC] Possible solution for min()/max() war
On Wed, 29 Aug 2001 20:28:20 -0700 (PDT), Linus Torvalds <> wrote:

> 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.
> 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".

And why should the compiler warn at all? The range of "int" completely
covers the range of "unsigned char", so the result of the comparison will
always be correct if the types were chosen correctly.

... unless of course the programmer used an unsigned char when what he
really wanted was a signed char. But in that case even your typed min
macro won't save him, because what should the forced type be anyway? If
it's "int", nothing changes; if it's "signed char", you risk truncating
the int. So you end up with something like

min(int, a, (char)b)

and I fail to see how this is any better than

min(a, (char)b)


It is better to keep your mouth shut and be thought a fool,
than to open it and remove all doubt.
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.164 / U:2.768 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site