[tz] [PROPOSED 4/7] Prefer C23 'alignof' to C11 '_Alignof'
Paul Eggert
eggert at cs.ucla.edu
Wed Oct 26 04:10:18 UTC 2022
* NEWS: Mention this.
* zic.c (alignof): Rename from _Alignof, with backward
compatibility substitute for pre-C23.
---
NEWS | 6 ++++--
zic.c | 8 +++++---
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index ac8de47..be85fe4 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Unreleased, experimental changes
zic now supports links to links, and vanguard form uses this.
Simplify four Ontario zones into one.
Fix a Y2438 bug when reading TZif data.
+ In C code, use some C23 features if available.
Changes to data
@@ -55,8 +56,9 @@ Unreleased, experimental changes
number 2438 comes from the 32-bit limit in the year 2038, plus the
400-year Gregorian cycle. (Problem reported by Bradley White.)
- Take advantage of the following C23 features if available:
- bool/true/false keywords, __has_include, unreachable.
+ In C code, prefer C23 keywords to pre-C23 macros for alignof,
+ bool, false, and true. Also, use the following C23 features if
+ available: __has_include, unreachable.
Release 2022e - 2022-10-11 11:13:02 -0700
diff --git a/zic.c b/zic.c
index a699285..e18506d 100644
--- a/zic.c
+++ b/zic.c
@@ -56,9 +56,11 @@ typedef int_fast64_t zic_t;
static ptrdiff_t const PTRDIFF_MAX = MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t));
#endif
-/* The minimum alignment of a type, for pre-C11 platforms. */
+/* The minimum alignment of a type, for pre-C23 platforms. */
#if __STDC_VERSION__ < 201112
-# define _Alignof(type) offsetof(struct { char a; type b; }, b)
+# define alignof(type) offsetof(struct { char a; type b; }, b)
+#elif __STDC_VERSION__ < 202311
+# include <stdalign.h>
#endif
/* The maximum length of a text line, including the trailing newline. */
@@ -2290,7 +2292,7 @@ writezone(const char *const name, const char *const string, char version,
/* Allocate the ATS and TYPES arrays via a single malloc,
as this is a bit faster. */
zic_t *ats = emalloc(align_to(size_product(nats, sizeof *ats + 1),
- _Alignof(zic_t)));
+ alignof(zic_t)));
void *typesptr = ats + nats;
unsigned char *types = typesptr;
struct timerange rangeall = {0}, range32, range64;
--
2.37.3
More information about the tz
mailing list