GCC 3.3.1, new warnings with <limits>
Bruce Evans
bde at zeta.org.au
Sun Jul 13 13:39:03 PDT 2003
On Sun, 13 Jul 2003, Marcel Moolenaar wrote:
> On Sun, Jul 13, 2003 at 08:23:54AM -0500, David Leimbach wrote:
> >
> > This is a good policy in general, however, one could easily argue that
> > what
> > is trying to be determined with signedness and such being
> > less-than-compared
> > to 0 isn't really a big deal and possibly the only way to implement this
> > numeric_limits<T>::digits thing without any type introspection which
> > C++ currently
> > lacks.
>
> What about?
>
> #define issigned(T) (((T)(0)>(T)(~0)) ? 1 : 0)
This is worse than any version that uses -1 instead of ~0, since ~0 gives
implementation-defined behaviour. I think it can set trap bits. Anyway,
the value of ~0 is unclear. I think it is -0 == 0 on 1's complement
machines. Since its value is unclear, the result of converting this value
to even an unsigned type T is also unclear. I think the above actually does
work for the 3 representations in C99 iff ~0 has no trap bits, but this is
unclear. These problems are avoided by using plain -1.
Bruce
More information about the freebsd-current
mailing list