GNU bug report logs - #8732
uinttostr: comparison of unsigned expression < 0 is always false

Previous Next

Package: coreutils;

Reported by: "Voelker, Bernhard" <bernhard.voelker <at> siemens-enterprise.com>

Date: Wed, 25 May 2011 18:20:02 UTC

Severity: normal

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


Message #19 received at 8732 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eric Blake <eblake <at> redhat.com>
Cc: bug-gnulib <bug-gnulib <at> gnu.org>, 8732 <at> debbugs.gnu.org
Subject: Re: bug#8732: uinttostr: comparison of unsigned expression < 0 is
	always	false
Date: Wed, 25 May 2011 15:21:18 -0700
On 05/25/11 14:48, Eric Blake wrote:
> This patch silences the gcc warning even for gcc too old to honor the
> pragma, but I can't help but feel that it might be too gross (it makes
> functions like uinttostr larger in size).
> ...
> -      *--p = '-';
> +      if (ii)
> +        *--p = '-';

Yes, it's too gross.  Once we start down that path we'll have a big
job of making subtle changes to code that make it worse
and are put in only to pacify GCC.  Compilers should be our servants,
not our masters, and in this case GCC serves us better by being quiet
about a matter that it doesn't grok.

> -#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
> +#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) <= 0)

This change I don't mind so much, as any compiler that can't optimize
0 * e - 1 <= 0 is unlikely to optimize 0 * e - 1 < 0 either.  It'd
need a comment.  If this sort of thing silences all the warnings it
might be worth doing.




This bug report was last modified 14 years and 55 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.