[PROPOSED 0/4] Port to C89, and deprecate C89
While looking into fixing some bugs in tzcode, I noticed some places where existing code wouldn’t work with ancient C89 compilers. I fixed the problems I found in this patch series. Quite possibly other problems remain, problems that I didn’t notice. As nobody has reported C89-related problems for ages, it appears that these old compilers are no longer being used to compile tzcode. So I propose that we remove C89 support, to avoid future maintenance burdens such as the one I recently went through. As part of the transition away from C89 support, the last patch in this series announces that C89 will be removed in some future release. We can keep C89 support for at least one release longer. Paul Eggert (4): Port to C89 gcc -pedantic Port UINT_FAST64_MAX back to C89 Port int_fast64_t to C89 64-bit long * NEWS: Deprecate C89. NEWS | 7 +++++++ private.h | 47 +++++++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 24 deletions(-) -- 2.38.1
* 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
The recent patch “Improve randomness of zic temp file names” used UINT_FAST64_MAX, which assumes C99. * private.h (UINT_FAST64_MAX): Define if not already defined. Reorganize the fallback a bit, to prefer long to long long if either will do. --- private.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/private.h b/private.h index b9d9765..aa6eb59 100644 --- a/private.h +++ b/private.h @@ -361,14 +361,13 @@ typedef unsigned long uint_fast32_t; #endif #ifndef UINT_FAST64_MAX -# ifdef ULLONG_MAX -typedef unsigned long long uint_fast64_t; +# if 3 <= ULONG_MAX >> 31 >> 31 +typedef unsigned long uint_fast64_t; +# define UINT_FAST64_MAX ULONG_MAX # else -# if ULONG_MAX >> 31 >> 1 < 0xffffffff -Please use a compiler that supports a 64-bit integer type (or wider); -you may need to compile with "-DHAVE_STDINT_H". -# endif -typedef unsigned long uint_fast64_t; +/* If this fails, compile with -DHAVE_STDINT_H or with a better compiler. */ +typedef unsigned long long uint_fast64_t; +# define UINT_FAST64_MAX ULLONG_MAX # endif #endif -- 2.38.1
* private.h (int_fast64_t, INT_FAST64_MIN, INT_FAST64_MAX) (PRIdFAST64): Prefer long to long long if either will do, as that works better on C89 platforms with 64-bit long. --- private.h | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/private.h b/private.h index aa6eb59..bdadd61 100644 --- a/private.h +++ b/private.h @@ -291,26 +291,23 @@ #endif #ifndef INT_FAST64_MAX -# ifdef LLONG_MAX -typedef long long int_fast64_t; -# define INT_FAST64_MIN LLONG_MIN -# define INT_FAST64_MAX LLONG_MAX -# else -# if LONG_MAX >> 31 < 0xffffffff -Please use a compiler that supports a 64-bit integer type (or wider); -you may need to compile with "-DHAVE_STDINT_H". -# endif -typedef long int_fast64_t; +# if 1 <= LONG_MAX >> 31 >> 31 +typedef long int_fast64_t; # define INT_FAST64_MIN LONG_MIN # define INT_FAST64_MAX LONG_MAX +# else +/* If this fails, compile with -DHAVE_STDINT_H or with a better compiler. */ +typedef long long int_fast64_t; +# define INT_FAST64_MIN LLONG_MIN +# define INT_FAST64_MAX LLONG_MAX # endif #endif #ifndef PRIdFAST64 -# if INT_FAST64_MAX == LLONG_MAX -# define PRIdFAST64 "lld" -# else +# if INT_FAST64_MAX == LONG_MAX # define PRIdFAST64 "ld" +# else +# define PRIdFAST64 "lld" # endif #endif -- 2.38.1
--- NEWS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 0fa732b..240bae8 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ News for the tz database Briefly: Fix some pre-1996 timestamps in northern Canada. + C89 is now deprecated; please use C99 or later. Portability fixes for AIX, libintl, MS-Windows, musl, z/OS C23 timegm now supported by default @@ -27,6 +28,12 @@ Unreleased, experimental changes Changes to code + Although tzcode still works with C89, bugs found in recent routine + maintenance indicate that bitrot has set in and that in practice + C89 is no longer used to build tzcode. As it is a maintenance + burden, support for C89 is planned to be removed soon. Instead, + please use compilers compatible with C99, C11, C17, or C23. + timegm, which tzcode implemented in 1989, will finally be standardized 34 years later as part of C23, so timegm is now supported even if STD_INSPIRED is not defined. -- 2.38.1
participants (1)
-
Paul Eggert