Re: Style question: comparison between signed and unsigned?

Gerard Roudier (groudier@club-internet.fr)
Wed, 24 Sep 1997 19:47:28 +0200 (MET DST)


On Wed, 24 Sep 1997, David Howells wrote:

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

Here is my contribution:

A cast will not fix that at all. It just will make the compiler quiet and
silent.
People who use BallsBreaker compilers tend to assume that a program that
compiles with no warning is just perfect.
Let me know where we've got improvement in code quality by using
such compilers that force programmers to use lots of casts in order
to distinguish between error messages and compiler's paranoia.

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

I donnot expect from a compiler to be clever. Not to be silly is enough.

Gerard.