Re: GCC 3.3.1, new warnings with <limits>

From: Jilles Tjoelker <jilles_at_stack.nl>
Date: Sun, 13 Jul 2003 17:21:54 +0200
On Sun, Jul 13, 2003 at 12:43:31AM -0400, Craig Rodrigues wrote:
> The warnings seemed to be caused by this code in 
> /usr/include/c++/3.3/limits:

> =========================================================================
>     630       static const int digits = __glibcpp_digits (unsigned int);
>     631       static const int digits10 = __glibcpp_digits10 (unsigned int);
> =========================================================================

> The macros are defined in the same file here:

> ============================================================================
>     134 #define __glibcpp_signed(T)     ((T)(-1) < 0)
>     
>     142 #define __glibcpp_digits(T) \
>     143   (sizeof(T) * __CHAR_BIT__ - __glibcpp_signed (T))
> ============================================================================

> The expanded macros look like:

> static const int digits = (sizeof(unsigned int) * 8 - ((unsigned int)(-1) < 0));
> static const int digits10 = ((sizeof(unsigned int) * 8 - ((unsigned int)(-1) < 0)) * 643 / 2136);

Perhaps this would work:

#define __glibcpp_signed(T)     (!((T)(-1) > 0))

I have tried this with GCC 3.2 (5.1-BETA i386, -W -Wall), and a plain C
program (not C++). cc and c++ do the same. The old macro gives the
warning about comparing signed types, but the new one does not. They
both work for int, u_int, unsigned int and char.

The compiler moans about (T)(-1) >= 0 as well. Is the assumption that
(unsigned type)(-1) is never zero valid?

If it's not, try (!((T)(-1) > 0 || (T)(-1) == 0)). GCC does not seem to
moan about that, even though it's exactly the same as using >=.

Jilles Tjoelker
Received on Sun Jul 13 2003 - 06:22:00 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:14 UTC