You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dean Gaudet <dg...@arctic.org> on 1997/09/22 22:21:32 UTC

-Wsign-compare

If someone is keen, it'd be interesting to see how many thousands of
warnings we get from -Wall on an egcs snapshot
<http://www.cygnus.com/egcs/>. 

Dean

---------- Forwarded message ----------
Date: Mon, 22 Sep 1997 16:57:22 +0200 (MET DST)
From: Thomas Koenig <ig...@mvmap66.ciw.uni-karlsruhe.de>
Reply-To: Thomas König <Th...@ciw.uni-karlsruhe.de>
To: linux-kernel@vger.rutgers.edu
Subject: Style question: comparison between signed and unsigned?

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.



---------- Forwarded message ----------
Date: Mon, 22 Sep 1997 11:38:03 -0400
From: Bill Hawes <wh...@star.net>
To: Thomas =?ISO-8859-1?Q?K=F6nig ?= <Th...@ciw.uni-karlsruhe.de>
Cc: linux-kernel@vger.rutgers.edu
Subject: Re: Style question: comparison between signed and unsigned?

Thomas Koenig wrote:
> 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?

I really dislike signed vs unsigned conversion bugs, and would certainly
prefer that new code avoid the situation.

But patches to fix warnings will need to be carefully considered, as
it's easy to accidentally introduce new problems.

Regards,
Bill



---------- Forwarded message ----------
Date: 22 Sep 1997 17:57:51 +0200
From: Ulrich Drepper <dr...@ipd.info.uni-karlsruhe.de>
To: linux-kernel@vger.rutgers.edu
Subject: Re: Style question: comparison between signed and unsigned?

Thomas Koenig <ig...@mvmap66.ciw.uni-karlsruhe.de> writes:

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

We've certainly eliminated several bugs by removing all these warnings
from glibc.  The benefit is also that you think twice about the types
of the variables.  Many people still unconditionally use `int's for
loop variables.  In many cases `unsigned int' is appropriate and it is
also faster in some cases on some platforms.  There are good reasons
for -Wall containing this option now.

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



---------- Forwarded message ----------
Date: Mon, 22 Sep 1997 18:29:54 +0100 (BST)
From: Mark Cooke <mp...@star.sr.bham.ac.uk>
To: Thomas König <Th...@ciw.uni-karlsruhe.de>
Cc: linux-kernel@vger.rutgers.edu
Subject: Re: Style question: comparison between signed and unsigned?

On Mon, 22 Sep 1997, Thomas Koenig wrote:

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

Signed/unsigned comparisions should (nearly) _always_ be avoided. It's a
symptom of inconsistancy/sloppy typedefs in the code. If it doesn't bite
you today, it might bite you tomorrow on a different architecture.

0.02c's worth

Mark

---------------------------------------------------------------------------
Mark Cooke                  The views expressed above are mine and are not
Systems Programmer          necessarily representative of university policy
University Of Birmingham    URL: http://www.sr.bham.ac.uk/~mpc/
---------------------------------------------------------------------------




---------- Forwarded message ----------
Date: 22 Sep 1997 13:09:39 -0500
From: Ulrich Drepper <dr...@ipd.info.uni-karlsruhe.de>
To: linux-kernel@vger.rutgers.edu
Subject: Re: Style question: comparison between signed and unsigned?

Thomas Koenig <ig...@mvmap66.ciw.uni-karlsruhe.de> writes:

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

We've certainly eliminated several bugs by removing all these warnings
from glibc.  The benefit is also that you think twice about the types
of the variables.  Many people still unconditionally use `int's for
loop variables.  In many cases `unsigned int' is appropriate and it is
also faster in some cases on some platforms.  There are good reasons
for -Wall containing this option now.

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



Re: -Wsign-compare

Posted by Alexei Kosut <ak...@nueva.pvt.k12.ca.us>.
On Mon, 22 Sep 1997, Dean Gaudet wrote:

> If someone is keen, it'd be interesting to see how many thousands of
> warnings we get from -Wall on an egcs snapshot
> <http://www.cygnus.com/egcs/>. 

We shouldn't get many. Microsoft Visual C++ complains about sign
comparisons, and it isn't easy (possible?) to turn off, so Ben fixed
most of them (except in mod_negotiation, I think) when he did the
Win32 stuff.

-- Alexei Kosut <ak...@nueva.pvt.k12.ca.us>