Subject: bug#8732: uinttostr: comparison of unsigned expression < 0 is always false

From: Paul Eggert <[email-masked]>
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.