From 455ce8e314f358c0a6fed436fc6a640de2f9d849 Mon Sep 17 00:00:00 2001 From: ryuukk <44361234+ryuukk@users.noreply.github.com> Date: Thu, 16 Jun 2022 01:36:22 +0200 Subject: [PATCH 1/2] Add alignof macro --- src/importc.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/importc.h b/src/importc.h index a15ceb80587..55da1a9efb3 100644 --- a/src/importc.h +++ b/src/importc.h @@ -55,3 +55,8 @@ * Define it to do what other C compilers do. */ #define __builtin_offsetof(t,i) ((typeof(sizeof(0)))((char *)&((t *)0)->i - (char *)0)) + +/**************************** + * Define it to do what other C compilers do. + */ +#define alignof(type) __builtin_offsetof(struct { char c; type member; }, member) From bc7ce9126e143e72a003e69cb70c1c6332658c0e Mon Sep 17 00:00:00 2001 From: ryuukk <44361234+ryuukk@users.noreply.github.com> Date: Sun, 26 Jun 2022 18:06:57 +0200 Subject: [PATCH 2/2] Correct align of macro for both gcc/clang --- src/importc.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/importc.h b/src/importc.h index 55da1a9efb3..7156c11fb7f 100644 --- a/src/importc.h +++ b/src/importc.h @@ -59,4 +59,9 @@ /**************************** * Define it to do what other C compilers do. */ -#define alignof(type) __builtin_offsetof(struct { char c; type member; }, member) +#define _Alignof(type) __builtin_offsetof(struct { char c; type member; }, member) + +/**************************** + * clang's preprocessor generates __alignof instead + */ +#define __alignof _Alignof