[PATCH] make kmod compatible with GCC < 4.6

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hello list, find attached a patch that fixes compilation with non-bleeding-edge compilers (we use GCC 4.5.4 in production).

the missing C11 feature is emulated on compilers that feature a __LINE__ macro.

best regards
--JS
[PATCH] make kmod compatible with GCC < 4.6

--- kmod-15.org/libkmod/macro.h
+++ kmod-15/libkmod/macro.h
@@ -21,8 +21,25 @@
 
 #include <stddef.h>
 
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ +0 >= 201112L) || \
+    (defined(__GNUC__) && (__GNUC__ +0) * 10 + (__GNUC_MINOR__ +0) >= 46)
+
 #define assert_cc(expr) \
 	_Static_assert((expr), #expr)
+
+#elif defined(__LINE__)
+
+#define PASTE2__(A, B) A ## B
+#define PASTE__(A, B) PASTE2__(A, B)
+#define STATIC_ASSERT__(COND) typedef char PASTE__(static_assertion, __LINE__) [(COND)?1:-1]
+#define assert_cc(expr) \
+	STATIC_ASSERT__((expr))
+
+#else
+#warning "compiler has no support for static assertions"
+#define assert_cc(expr) do {} while(0)
+
+#endif
 
 #if HAVE_TYPEOF
 #define check_types_match(expr1, expr2)		\

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux