Messages in this thread | | | From | "Peter T. Breuer" <> | Subject | Re: [IDEA+RFC] Possible solution for min()/max() war | Date | Fri, 31 Aug 2001 14:13:33 +0200 (CEST) |
| |
"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.
Peter - 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/
| |