[lkml]   [2001]   [Aug]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [IDEA+RFC] Possible solution for min()/max() war
"A month of sundays ago Roman Zippel wrote:"
> On Fri, 31 Aug 2001, Peter T. Breuer wrote:
> > if (sizeof(_x) != sizeof(_y)) \
> > MIN_BUG(); \
> What bug are you trying to fix here?

Wake up!

> > int main() {
> > unsigned i = 1;
> > signed j = -2;
> > return MIN(i,j);
> > }
> Try -Wsign-compare.

Wake up harder!

Try reading the last 10 days kernel messages. The last 48 hours are
particularly rewarding.

To be honest, nobody has precisely formulated the problem. I'll attempt
a quick summary of the most salient:

C silently transforms signed int to unsigned int in cross-signed
comparisons. This results in 1U < -2, and gives rise to all kinds
of error paths from min/max codes (in particular, but they're not
all) of the form

min(unsigned_positive_constant, signed_ok_or_error_value)

whose authors were expecting to get the error value out when the
error value went in!

There are apparently more problems too, but nobody has explained them
to me in a manner that I can comprehend. I suspect that nobody knows
the full range of possible faults. I put in the size comparison
that you remarked upon so that people could tell me about it. Tell me
about it.

Linus wants possible mistakes flagged. He specifically does not want
-Wsign-compare because it apparently gives false positives.

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.226 / U:0.660 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site