/* Two gcc extensions.
* &a[0] degrades to a pointer: a different type from an array */
#define _array_size_chk(arr) \
- EXPR_BUILD_ASSERT(!__builtin_types_compatible_p(typeof(arr), \
+ BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \
typeof(&(arr)[0])))
#else
#define _array_size_chk(arr) 0
do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
/**
- * EXPR_BUILD_ASSERT - assert a build-time dependency, as an expression.
+ * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
* @cond: the compile-time condition which must be true.
*
* Your compile will fail if the condition isn't true, or can't be evaluated
* Example:
* #define foo_to_char(foo) \
* ((char *)(foo) \
- * + EXPR_BUILD_ASSERT(offsetof(struct foo, string) == 0))
+ * + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
*/
-#define EXPR_BUILD_ASSERT(cond) \
+#define BUILD_ASSERT_OR_ZERO(cond) \
(sizeof(char [1 - 2*!(cond)]) - 1)
#endif /* CCAN_BUILD_ASSERT_H */
int main(int argc, char *argv[])
{
#ifdef FAIL
- return EXPR_BUILD_ASSERT(1 == 0);
+ return BUILD_ASSERT_OR_ZERO(1 == 0);
#else
return 0;
#endif
--- /dev/null
+#include <ccan/build_assert/build_assert.h>
+#include <ccan/tap/tap.h>
+
+int main(int argc, char *argv[])
+{
+ plan_tests(1);
+ ok1(BUILD_ASSERT_OR_ZERO(1 == 1) == 0);
+ return exit_status();
+}
+++ /dev/null
-#include <ccan/build_assert/build_assert.h>
-#include <ccan/tap/tap.h>
-
-int main(int argc, char *argv[])
-{
- plan_tests(1);
- ok1(EXPR_BUILD_ASSERT(1 == 1) == 0);
- return exit_status();
-}
*/
#define cast_signed(type, expr) \
((type)(expr) \
- + EXPR_BUILD_ASSERT(cast_sign_compatible(type, (expr))))
+ + BUILD_ASSERT_OR_ZERO(cast_sign_compatible(type, (expr))))
/**
* cast_const - remove a const qualifier from a pointer.
*/
#define cast_const(type, expr) \
((type)(expr) \
- + EXPR_BUILD_ASSERT(cast_const_compat1((expr), type)))
+ + BUILD_ASSERT_OR_ZERO(cast_const_compat1((expr), type)))
/**
* cast_const2 - remove a const qualifier from a pointer to a pointer.
*/
#define cast_const2(type, expr) \
((type)(expr) \
- + EXPR_BUILD_ASSERT(cast_const_compat2((expr), type)))
+ + BUILD_ASSERT_OR_ZERO(cast_const_compat2((expr), type)))
/**
* cast_const3 - remove a const from a pointer to a pointer to a pointer..
*/
#define cast_const3(type, expr) \
((type)(expr) \
- + EXPR_BUILD_ASSERT(cast_const_compat3((expr), type)))
+ + BUILD_ASSERT_OR_ZERO(cast_const_compat3((expr), type)))
/**
#include <ccan/build_assert/build_assert.h>
/* Without typeof, we can only test the sizes. */
#define check_type(expr, type) \
- EXPR_BUILD_ASSERT(sizeof(expr) == sizeof(type))
+ BUILD_ASSERT_OR_ZERO(sizeof(expr) == sizeof(type))
#define check_types_match(expr1, expr2) \
- EXPR_BUILD_ASSERT(sizeof(expr1) == sizeof(expr2))
+ BUILD_ASSERT_OR_ZERO(sizeof(expr1) == sizeof(expr2))
#endif /* HAVE_TYPEOF */
#endif /* CCAN_CHECK_TYPE_H */
* }
*/
#define hash_stable(p, num, base) \
- (EXPR_BUILD_ASSERT(sizeof(*(p)) == 8 || sizeof(*(p)) == 4 \
- || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
+ (BUILD_ASSERT_OR_ZERO(sizeof(*(p)) == 8 || sizeof(*(p)) == 4 \
+ || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
sizeof(*(p)) == 8 ? hash_stable_64((p), (num), (base)) \
: sizeof(*(p)) == 4 ? hash_stable_32((p), (num), (base)) \
: sizeof(*(p)) == 2 ? hash_stable_16((p), (num), (base)) \
* }
*/
#define hash64_stable(p, num, base) \
- (EXPR_BUILD_ASSERT(sizeof(*(p)) == 8 || sizeof(*(p)) == 4 \
- || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
+ (BUILD_ASSERT_OR_ZERO(sizeof(*(p)) == 8 || sizeof(*(p)) == 4 \
+ || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
sizeof(*(p)) == 8 ? hash64_stable_64((p), (num), (base)) \
: sizeof(*(p)) == 4 ? hash64_stable_32((p), (num), (base)) \
: sizeof(*(p)) == 2 ? hash64_stable_16((p), (num), (base)) \
* This is either hash() or hash64(), on 32/64 bit long machines.
*/
#define hashl(p, num, base) \
- (EXPR_BUILD_ASSERT(sizeof(long) == sizeof(uint32_t) \
- || sizeof(long) == sizeof(uint64_t)) + \
+ (BUILD_ASSERT_OR_ZERO(sizeof(long) == sizeof(uint32_t) \
+ || sizeof(long) == sizeof(uint64_t)) + \
(sizeof(long) == sizeof(uint64_t) \
? hash64((p), (num), (base)) : hash((p), (num), (base))))