Jim Meyering wrote: > Which macros from <stdint.h> would be better?
I was thinking of INT64_MIN, INT64_MAX, UINT64_MAX. But using these would assume that 'long long' has 64 bits, which is not future-proof... > Using LLONG_MIN etc. sounds fine. OK, I'm using this. If on some platforms, LLONG_MIN is undefined, it will get reported, and we'll find some replacement. (Remember that LONG_LONG_MIN as a fallback is only available with GCC, AFAICS.) 2010-03-14 Bruno Haible <[email protected]> Fix compilation error with Sun C. * lib/strtol.c: Use LLONG_MIN instead of GCC specific LONG_LONG_MIN. Use LLONG_MAX instead of GCC specific LONG_LONG_MAX. Use ULLONG_MAX instead of GCC specific ULONG_LONG_MAX. * lib/xstrtoll.c: Likewise. * lib/xstrtoull.c: Likewise. --- lib/strtol.c.orig Sun Mar 14 19:20:28 2010 +++ lib/strtol.c Sun Mar 14 17:15:07 2010 @@ -114,9 +114,9 @@ operating on `long long int's. */ #ifdef QUAD # define LONG long long -# define STRTOL_LONG_MIN LONG_LONG_MIN -# define STRTOL_LONG_MAX LONG_LONG_MAX -# define STRTOL_ULONG_MAX ULONG_LONG_MAX +# define STRTOL_LONG_MIN LLONG_MIN +# define STRTOL_LONG_MAX LLONG_MAX +# define STRTOL_ULONG_MAX ULLONG_MAX /* The extra casts in the following macros work around compiler bugs, e.g., in Cray C 5.0.3.0. */ @@ -147,19 +147,19 @@ ? (t) -1 \ : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) -# ifndef ULONG_LONG_MAX -# define ULONG_LONG_MAX TYPE_MAXIMUM (unsigned long long) +# ifndef ULLONG_MAX +# define ULLONG_MAX TYPE_MAXIMUM (unsigned long long) # endif -# ifndef LONG_LONG_MAX -# define LONG_LONG_MAX TYPE_MAXIMUM (long long int) +# ifndef LLONG_MAX +# define LLONG_MAX TYPE_MAXIMUM (long long int) # endif -# ifndef LONG_LONG_MIN -# define LONG_LONG_MIN TYPE_MINIMUM (long long int) +# ifndef LLONG_MIN +# define LLONG_MIN TYPE_MINIMUM (long long int) # endif # if __GNUC__ == 2 && __GNUC_MINOR__ < 7 /* Work around gcc bug with using this constant. */ - static const unsigned long long int maxquad = ULONG_LONG_MAX; + static const unsigned long long int maxquad = ULLONG_MAX; # undef STRTOL_ULONG_MAX # define STRTOL_ULONG_MAX maxquad # endif --- lib/xstrtoll.c.orig Sun Mar 14 19:20:28 2010 +++ lib/xstrtoll.c Sun Mar 14 17:15:08 2010 @@ -1,6 +1,6 @@ #define __strtol strtoll #define __strtol_t long long int #define __xstrtol xstrtoll -#define STRTOL_T_MINIMUM LONG_LONG_MIN -#define STRTOL_T_MAXIMUM LONG_LONG_MAX +#define STRTOL_T_MINIMUM LLONG_MIN +#define STRTOL_T_MAXIMUM LLONG_MAX #include "xstrtol.c" --- lib/xstrtoull.c.orig Sun Mar 14 19:20:28 2010 +++ lib/xstrtoull.c Sun Mar 14 17:15:08 2010 @@ -2,5 +2,5 @@ #define __strtol_t unsigned long long int #define __xstrtol xstrtoull #define STRTOL_T_MINIMUM 0 -#define STRTOL_T_MAXIMUM ULONG_LONG_MAX +#define STRTOL_T_MAXIMUM ULLONG_MAX #include "xstrtol.c"
