/*#*
*#* $Log$
+ *#* Revision 1.11 2006/02/20 14:34:58 bernie
+ *#* Use portable type checking.
+ *#*
*#* Revision 1.10 2006/02/15 09:12:01 bernie
*#* Fixes for ARM/IAR support.
*#*
#define DEPRECATED __attribute__((__deprecated__))
#endif
+ #ifndef __cplusplus
+ #define ASSERT_TYPE_EQUAL(var1, var2) \
+ STATIC_ASSERT(__builtin_types_compatible_p(typeof(var1), typeof(var2)))
+ #define ASSERT_TYPE_IS(var, type) \
+ STATIC_ASSERT(__builtin_types_compatible_p(typeof(var), type))
+ #endif
+
/* Include some standard C89/C99 stuff */
#include <stddef.h>
#include <stdint.h>
/*! Issue a compilation error if the \a condition is false */
#define STATIC_ASSERT(condition) \
- UNUSED_VAR(extern char,PP_CAT(CT_ASSERT___, __LINE__)[(condition) ? 1 : -1])
+ UNUSED_VAR(extern char, STATIC_ASSERTION_FAILED__[(condition) ? 1 : -1])
+
+#ifndef ASSERT_TYPE_EQUAL
+/*! Ensure two variables have the same type. */
+#define ASSERT_TYPE_EQUAL(var1, var2) \
+ do { (void)(&(var1) == &(var2)); } while(0)
+#endif
+
+#ifndef ASSERT_TYPE_IS
+/*! Ensure variable is of specified type. */
+#define ASSERT_TYPE_IS(var, type) \
+ do { (void)(&var == (type *)0); } while(0)
+#endif
#endif /* DEVLIB_COMPILER_H */
/*#*
*#* $Log$
+ *#* Revision 1.7 2006/02/20 14:34:58 bernie
+ *#* Use portable type checking.
+ *#*
*#* Revision 1.6 2006/02/10 12:36:57 bernie
*#* Pacify IAR warnings for side-effects.
*#*
#define MIN(a,b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
- (void)(&_a == &_b); /* ensure same type */ \
+ ASSERT_TYPE_EQUAL(_a, _b); \
(_a < _b) ? _a : _b; \
})
#define MAX(a,b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
- (void)(&_a == &_b); /* ensure same type */ \
+ ASSERT_TYPE_EQUAL(_a, _b); \
(_a > _b) ? _a : _b; \
})
#else /* !(COMPILER_STATEMENT_EXPRESSIONS && COMPILER_TYPEOF) */
*/
#define SWAP(a, b) \
do { \
- (void)(&(a) == &(b)); /* type check */ \
typeof(a) tmp; \
+ ASSERT_TYPE_EQUAL(a, b); \
tmp = (a); \
(a) = (b); \
(b) = tmp; \