Re: Style question: comparison between signed and unsigned?

David Howells (
Wed, 24 Sep 1997 09:20:31 BST

Well, just to stick my contribution in to this topic...

Take the following code:

void fred(unsigned int X) {
int Y;
Y = X;

I think this should cause a warning because an unsigned int goes from 0 to
+4,000,000,000 (approx), and an int goes from -2,000,000,000 to +2,000,000,000
(approx). So it is therefore possible for X in the above example to hold a
value that can't be represented in Y (the reverse is also true).

What you want is to be able to switch off the warning about signed/unsigned
conversion when required without having to use a cast operator (which makes
the code unsightly).

Even better, a clever compiler that can tell the difference...

David Howells