From bac3f93772bdf8618c2c9677c59569d70e4a39c0 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Tue, 11 Feb 2020 17:26:34 +0100 Subject: [PATCH] lib/zt_common: add STATIC_ASSERT macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `STATIC_ASSERT` macro that uses `_Static_assert` if available (was introduced with gcc 4.6, see https://gcc.gnu.org/wiki/C11Status). For example, this could be used for the verification of structure sizes at compile time. Acked-by: Jan Höppner Signed-off-by: Marc Hartmayer Signed-off-by: Jan Höppner --- include/lib/zt_common.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/lib/zt_common.h b/include/lib/zt_common.h index 68f8af01..ddc75504 100644 --- a/include/lib/zt_common.h +++ b/include/lib/zt_common.h @@ -22,6 +22,13 @@ # define UNUSED(x) x #endif +#ifdef STATIC_ASSERT +#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ >= 5) +# define STATIC_ASSERT(test) _Static_assert((test), "(" #test ") failed"); +#else +# define STATIC_ASSERT(test) +#endif + #define RELEASE_STRING STRINGIFY (S390_TOOLS_RELEASE) #define TOOLS_LIBDIR STRINGIFY (S390_TOOLS_LIBDIR) #define TOOLS_SYSCONFDIR STRINGIFY (S390_TOOLS_SYSCONFDIR)