build: fix compilation if _Static_assert() is not available
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sat, 29 Sep 2012 08:13:45 +0000 (10:13 +0200)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sat, 29 Sep 2012 08:13:45 +0000 (10:13 +0200)
I just noticed that older compiles do not support _Static_assert() so we
now check in configure.ac for it. We do not use it heavily, anyway.
Dynamic asserts are avoided entirely.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
configure.ac
src/uterm_input_plain.c

index fdd4205..e0b93b8 100644 (file)
@@ -243,6 +243,17 @@ AM_CONDITIONAL([BUILD_ENABLE_DEBUG],
 AM_CONDITIONAL([BUILD_ENABLE_OPTIMIZATIONS],
                [test x$optimizations_enabled = xyes])
 
+# check for _Static_assert
+AC_MSG_CHECKING([whether _Static_assert() is supported])
+AC_LANG([C])
+have_static_assert=yes
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[_Static_assert(1, "What?");]])],
+                  [AC_DEFINE([BUILD_HAVE_STATIC_ASSERT],
+                             [1],
+                             [Define to 1 if _Static_assert() is supported])],
+                  [have_static_assert=no])
+AC_MSG_RESULT([$have_static_assert])
+
 #
 # Main applications
 # This checks which applications to build so we can optionally disable unused
index 3a7e30c..44de350 100644 (file)
@@ -162,10 +162,12 @@ static const uint32_t keytab_normal[] = {
 
 #define KEYTAB_SIZE (KEY_RIGHTMETA + 1)
 
+#ifdef BUILD_HAVE_STATIC_ASSERT
 _Static_assert(
        (KEYTAB_SIZE == sizeof(keytab_normal) / sizeof(*keytab_normal)),
        "The KEYTAB_SIZE #define is incorrect!"
 );
+#endif
 
 static const uint32_t keytab_numlock[KEYTAB_SIZE] = {
        [KEY_KP7]         =  XKB_KEY_KP_7,