]> rtime.felk.cvut.cz Git - ulut.git/commitdiff
Const and volatile qualifiers removal (UL_CAST_UNQX) which supports global initializers.
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Fri, 5 Sep 2014 17:25:08 +0000 (19:25 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Fri, 5 Sep 2014 17:25:08 +0000 (19:25 +0200)
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
ulut/ul_utdefs.h

index b00ea9207b41539305555bc0f2defa6417225d09..adee9bda5443d5eece4e343946949b42a61a14fb 100644 (file)
@@ -151,13 +151,22 @@ extern "C" {
   typeof(ref_asterisks(union { int z; typeof(ptr_type) x; }){0}.x)
 
 #ifdef __GNUC__
-#define UL_CAST_UNQX(ref_asterisks, new_type, expr) ({ \
-  UL_BUILD_BUG_ON_MSG(!__builtin_types_compatible_p\
+/* Const and volatile qualifiers removal cast
+ * The expression is cast by (typeof((typeof(new_type[1])){0}[0]))
+ * which is equivalent to (new_type) cast for matching types.
+ * This quite complicated method is used because both comma operator
+ * and compound expressions are not allowed in global variables
+ * initializers.
+ */
+#define UL_CAST_UNQX(ref_asterisks, new_type, expr) ( \
+  (typeof((typeof(new_type[1 - 2 * \
+    !__builtin_types_compatible_p \
     (UL_TYPEOF_REFX(ref_asterisks, expr), \
-     UL_TYPEOF_REFX(ref_asterisks,new_type)), \
-       "Qualifiers stripping cast to incompatible type"); \
-  (new_type)(expr); \
-})
+     UL_TYPEOF_REFX(ref_asterisks, new_type)) \
+    ])){0}[0]) \
+  ) \
+  (expr) \
+)
 #else /*__GNUC__*/
 #define UL_CAST_UNQX(ref_asterisks, new_type, expr) ((new_type)(expr))
 #endif /*__GNUC__*/