[cfe-commits] r63977 - in /cfe/trunk/lib/Headers: limits.h stdint.h
Eli Friedman
eli.friedman at gmail.com
Fri Feb 6 17:25:33 PST 2009
On Fri, Feb 6, 2009 at 2:59 PM, Chris Lattner <sabre at nondot.org> wrote:
> +#define INT8_MAX ((int8_t)127)
> +#define INT8_MIN ((int8_t)-128)
> +#define UINT8_MAX ((uint8_t)255)
Gah! I can't believe I didn't spot this. Casts aren't allowed here.
In this case, they're unnecessary anyway.
> +#define INT16_MAX ((int16_t)32767)
> +#define INT16_MIN ((int16_t)-32768)
> +#define UINT16_MAX ((uint16_t)(65535))
Same issue. As long as the 65535 is marked unsigned, the casts are
unnecessary due to integer promotions.
> +#define INT32_MAX ((int32_t)2147483647LL)
> +#define INT32_MIN ((int32_t)(-2147483647LL-1))
> +#define UINT32_MAX ((uint32_t)4294967295ULL)
Same issue; you'll need some ifdefs to get this right for platforms
where int32_t isn't int. Note that the rule is that INT32_MAX is
required to have type int32_t.
> +#define INT64_MAX ((int64_t)9223372036854775807LL)
> +#define INT64_MIN ((int64_t)(-9223372036854775807LL-1))
> +#define UINT64_MAX ((uint64_t)18446744073709551615ULL)
Same issue. Also, this is wrong if int64_t doesn't map to long long;
do we make any guarantees here?
> +/* C99 7.18.2.5 Limits of greatest-width integer types. */
> +#define INTMAX_MIN (-__INTMAX_MAX__-1)
> +#define INTMAX_MAX __INTMAX_MAX__
> +#define UINTMAX_MAX (__INTMAX_MAX__*2+1)
Not that there's an issue here, but it's probably worth
double-checking that __INTMAX_MAX__ has the right type.
> +#define INT64_C(v) (v##LL)
> +#define UINT64_C(v) (v##ULL)
Do we guarantee int64_t == long long?
> +/* 7.18.4.2 Macros for greatest-width integer constants. */
> +#define INTMAX_C(v) (v ## LL)
> +#define UINTMAX_C(v) (v ## ULL)
This is wrong for targets where intmax_t != long long.
-Eli
More information about the cfe-commits
mailing list