Style question: comparison between signed and unsigned?

Thomas Koenig (ig25@mvmap66.ciw.uni-karlsruhe.de)
Mon, 22 Sep 1997 16:57:22 +0200 (MET DST)


The current egcs snapshot includes -Wsign-compare in -Wall, which
warns about unexpected cases like

int n;

n = some_func();
if (n > sizeof(int)) {
/* This branch gets taken for n == -1 */
}

and generates a ton of "warning: comparison between signed and unsigned"
messages when compiling the 2.0.30 kernel.

I'm sure that most of these don't matter, but I've been bitten once
by the bug above in Linux libc (the bug which caused the portmapper
to loop on -ECONNREFUSED), and I think it's quite possible that some
bugs may lurk in the kernel because of this. I've had a look at some
of these cases, and I didn't feel sure that some cases could not
produce an error.

What do other people feel? Should signed/unsigned conversions be
avoided in new code? Should these be eliminated in 2.2? Will patches
towards that goal be accepted if all they do is clean up error
messages?

-- 
Thomas Koenig, Thomas.Koenig@ciw.uni-karlsruhe.de, ig25@dkauni2.bitnet.
The joy of engineering is to find a straight line on a double
logarithmic diagram.