Re: Style question: comparison between signed and unsigned?

Ulrich Drepper (drepper@ipd.info.uni-karlsruhe.de)
23 Sep 1997 22:50:54 +0200


"Theodore Y. Ts'o" <tytso@MIT.EDU> writes:

> It's an awful lot of work.

Don't tell me, I know it. What do you think the situation was before
we cleaned glibc? Now we have only a few warnings left and these are
caused by gcc limited analysis abilities or the bugs in other programs
(namely gperf).

> Right now it's very easy, with a very big source tree (krb5 has
> literally hundreds of files), to scan the MAKELOG file, and find
> warnings which need to be fixed.

For glibc we had to fix around >1000 files.

> Checking all possible warnings each time I compile this huge source
> tree is simply and plainly impossible.

No, it's not. Simply force that all warnings are removed by
classifying them as errors. So it is easy to stay on this track once
the work is done.

> Even with a package that's completely under my control, I don't want to
> have to remember that a particular warning is meaningless --- how often
> do *you* remember that line 415's signed/unsigned mismatch is harmless,
> but line 750's signed/unsigned mismatch represents a real bug?

I don't need to remember. I look at the sources, change the type of
the involved variables/expressions or add a cast. The point is that
*I* decided what is correct and don't rely on the compiler making the
decision for me. Once I fixed this I never again see the line 415
warning.

Enabling this warning simply makes programming more safe. Since I
have to deal with these warnings I think twice when using a loop
variable. Before I often used `int's to index array etc especially
when counting downwards. Now I always use unsigned types if possible
and so simply avoid warnings. And I get rid of this unsafe feeling
that the compiler might interpret an expression differently because of
signed<->unsigned differences.

>From your argumentation I haven't read that you are against having
this option around for newly developed code. You seem to care for old
code. But than this is only argument of somebody who wants to avoid
work. If you are not willing to spend this time go on and disable
this warning. Maybe you can re-enable it once you cleaned your
sources. But -Wall should definitely contain these warnings since so
newly developed code is written correctly right from the start.

-- Uli
---------------. drepper@cygnus.com ,-. Rubensstrasse 5
Ulrich Drepper \ ,-------------------' \ 76149 Karlsruhe/Germany
Cygnus Solutions `--' drepper@gnu.ai.mit.edu `------------------------