changeset 5449:bca896b09c7a HEAD

Added HAVE_TYPEOF, COMPILE_ERROR_IF_TRUE() and COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE() macros.
author Timo Sirainen <tss@iki.fi>
date Thu, 29 Mar 2007 14:48:18 +0300
parents beabd433cdae
children 7a6db5ec047d
files src/lib/macros.h
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/macros.h	Thu Mar 29 10:59:11 2007 +0300
+++ b/src/lib/macros.h	Thu Mar 29 14:48:18 2007 +0300
@@ -142,6 +142,18 @@
 	name(__VA_ARGS__, (callback_type *)callback, context)
 #endif
 
+#ifdef __GNUC__
+#  define HAVE_TYPEOF
+#  define COMPILE_ERROR_IF_TRUE(condition) \
+	(sizeof(char[1 - 2 * !!(condition)]) - 1)
+#  define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) \
+	COMPILE_ERROR_IF_TRUE( \
+		!__builtin_types_compatible_p(typeof(_a), typeof(_b)))
+#else
+#  define COMPILE_ERROR_IF_TRUE(condition) 0
+#  define COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(_a, _b) 0
+#endif
+
 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
    macros, so we can refer to them as strings unconditionally. */
 #ifdef __GNUC__