Skip to content

Commit

Permalink
Port to C89 gcc -pedantic
Browse files Browse the repository at this point in the history
* 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__.
  • Loading branch information
eggert committed Nov 19, 2022
1 parent f4ca780 commit 85a4b4a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -370,15 +373,15 @@ 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;
# endif
#endif

#ifndef PRIuMAX
# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
# ifdef ULLONG_MAX
# define PRIuMAX "llu"
# else
# define PRIuMAX "lu"
Expand Down

0 comments on commit 85a4b4a

Please sign in to comment.