[glib/nirbheek/static-assert-c11] gmacros: Use _Static_assert when C11 is available
- From: Nirbheek Chauhan <nirbheekc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/nirbheek/static-assert-c11] gmacros: Use _Static_assert when C11 is available
- Date: Thu, 27 Jun 2019 08:10:47 +0000 (UTC)
commit 67cc8187d4f809d42a9e12ff0f1b92927762faaf
Author: Nirbheek Chauhan <nirbheek centricular com>
Date: Thu Jun 27 13:37:58 2019 +0530
gmacros: Use _Static_assert when C11 is available
The static assert message is much nicer to read, and is less likely to
be misinterpreted as a false positive.
glib is built with `-std=gnu89`, but this macro will be available to
projects that use glib with c11 or gnu11.
glib/gmacros.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 1c8d64699..a4a4591ae 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -734,13 +734,18 @@
#ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
#define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
+#if __STDC_VERSION__ >= 201112L
+#define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
+#define G_STATIC_ASSERT_EXPR(expr) _Static_assert (expr, "Expression evaluates to false")
+#else
#ifdef __COUNTER__
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr)
? 1 : -1] G_GNUC_UNUSED
#else
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ?
1 : -1] G_GNUC_UNUSED
#endif
#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
-#endif
+#endif /* __STDC_VERSION__ */
+#endif /* !__GI_SCANNER__ */
/* Provide a string identifying the current code position */
#if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]