[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gnulib] proposed simplification rewrite of stdint module
From: |
Bruno Haible |
Subject: |
Re: [bug-gnulib] proposed simplification rewrite of stdint module |
Date: |
Fri, 30 Jun 2006 14:34:49 +0200 |
User-agent: |
KMail/1.9.1 |
Paul Eggert wrote:
> > : ((((zero) + 1) << ((bits) ? (bits) - 1 : 0)) - 1) * 2 + 1)
>
> Hmm, that's not quite right either, surely you meant (bits) - 2.
No, it appears correct as it is. For example, if bits==32, it will be
((1U << 31) - 1) * 2 + 1)
= (0x7fffffffU * 2 + 1)
= 0xffffffffU
> But I now thought of a simpler definition. _STDINT_MAX needs only
> two arguments, and can be simplified to:
>
> /* _STDINT_MAX relies on the signedness of 'zero' to return the
> correct type. */
> #define _STDINT_MAX(bits, zero) (~ _STDINT_MIN (1, bits, zero))
Are you sure this will work for bits < 32? For example, for bits==16
it will evaluate to 0xffffffffU, not 0xffffU.
> OK, I'll change it to this, which follows the advice you gave:
>
> #define int_fast8_t long int
> #define uint_fast8_t unsigned int_fast8_t
> #define int_fast16_t long int
> #define uint_fast16_t unsigned int_fast16_t
> #define int_fast32_t long int
> #define uint_fast32_t unsigned int_fast32_t
Thanks. That should be fine on all systems.
Bruno