Date: Sun, 13 Jul 2003 17:21:54 +0200 From: Jilles Tjoelker <jilles@stack.nl> To: Craig Rodrigues <rodrigc@crodrigues.org> Cc: freebsd-current@freebsd.org Subject: Re: GCC 3.3.1, new warnings with <limits> Message-ID: <20030713152154.GA96653@stack.nl> In-Reply-To: <20030713044331.GA89785@crodrigues.org> References: <20030712155333.GA79322@crodrigues.org> <BEDC8C48-B4DC-11D7-BE3B-0003937E39E0@mac.com> <20030713031312.GA89014@crodrigues.org> <20030713000559.28c18be6.kabaev@mail.ru> <20030713044331.GA89785@crodrigues.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030713152154.GA96653>