[tz] [PROPOSED 1/4] Port to C89 gcc -pedantic
Paul Eggert
eggert at cs.ucla.edu
Sat Nov 19 20:41:32 UTC 2022
* private.h (HAVE_GENERIC, LLONG_MAX, LLONG_MIN):
Don’t define if compiled with gcc -std=c89 -pedantic,
since that GCC diagnoses _Generic and long long.
(ULLONG_MAX): Define if not already defined, and
if __LONG_LONG_MAX__ and !__STRICT_ANSI__.
(uint_fast64_t, uintmax_t, PRIuMAX):
Rely on ULLONG_MAX, not __LONG_LONG_MAX__.
---
private.h | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/private.h b/private.h
index 7320173..b9d9765 100644
--- a/private.h
+++ b/private.h
@@ -56,7 +56,7 @@
# endif
#endif
/* _Generic is buggy in pre-4.9 GCC. */
-#if !defined HAVE_GENERIC && defined __GNUC__
+#if !defined HAVE_GENERIC && defined __GNUC__ && !defined __STRICT_ANSI__
# define HAVE_GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__))
#endif
#ifndef HAVE_GENERIC
@@ -278,13 +278,16 @@
#endif
/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
-#ifdef __LONG_LONG_MAX__
+#if defined __LONG_LONG_MAX__ && !defined __STRICT_ANSI__
# ifndef LLONG_MAX
# define LLONG_MAX __LONG_LONG_MAX__
# endif
# ifndef LLONG_MIN
# define LLONG_MIN (-1 - LLONG_MAX)
# endif
+# ifndef ULLONG_MAX
+# define ULLONG_MAX (LLONG_MAX * 2ull + 1)
+# endif
#endif
#ifndef INT_FAST64_MAX
@@ -358,7 +361,7 @@ typedef unsigned long uint_fast32_t;
#endif
#ifndef UINT_FAST64_MAX
-# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
+# ifdef ULLONG_MAX
typedef unsigned long long uint_fast64_t;
# else
# if ULONG_MAX >> 31 >> 1 < 0xffffffff
@@ -370,7 +373,7 @@ typedef unsigned long uint_fast64_t;
#endif
#ifndef UINTMAX_MAX
-# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
+# ifdef ULLONG_MAX
typedef unsigned long long uintmax_t;
# else
typedef unsigned long uintmax_t;
@@ -378,7 +381,7 @@ typedef unsigned long uintmax_t;
#endif
#ifndef PRIuMAX
-# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
+# ifdef ULLONG_MAX
# define PRIuMAX "llu"
# else
# define PRIuMAX "lu"
--
2.38.1
More information about the tz
mailing list