bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: warning: comparison is always false due to limited range of data typ


From: Paul Eggert
Subject: Re: warning: comparison is always false due to limited range of data type
Date: Wed, 31 Aug 2005 10:52:37 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Jim Meyering <address@hidden> writes:

> Is there a patch yet to make gcc suppress that warning?

Sorry, not yet.  Other things are on my plate....

> -      unsigned int n1 = n0 + 1;
> +      /* FIXME: technically, the type of n1 should be `unsigned int',
> +      but that evokes an unsuppressible warning from gcc-4.0.1 and
> +      older.  If gcc ever provides an option to suppress that warning,
> +      revert to the original type, so that the test in xalloc_oversized
> +      is once again performed only at compile time.  */
> +      size_t n1 = n0 + 1;

That doesn't look quite right in general: suppose size_t is narrower
than unsigned int?  Admittedly it's a theoretical problem, but we
might as well do it right if it's easy.

Also, I'd rather not penalize all compilers just because GCC is busted.

Personally I'd rather leave the code alone and filter out the messages
some other way.  But if they really bother you how about this instead?

   #if __GNUC__
   # include "size_max.h"
   #endif
   ...
   #if __GNUC__ && UINT_MAX < SIZE_MAX
       /* FIXME comment, as above.  */
       size_t n1 = n0 + 1;
   #else
       unsigned int n1 = n0 + 1;
   #endif

That way, non-GCC compilers can have the improved performance.

This will cause quotearg to depend on the size_max module, but that's
a lightweight module so it should be OK.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]