Here is an assert that is static if possible:
#ifndef __clang__
#define assume(expr) \
__extension__ ({ \
static_assert(__builtin_choose_expr( \
__builtin_constant_p(expr), expr, true), #expr); \
assert(__builtin_choose_expr( \
__builtin_constant_p(expr), true, expr)); \
})
#else
#define assume(expr) \
__extension__ ({ \
static_assert(__builtin_constant_p(expr) ? (expr) : true, #expr); \
assert(__builtin_choose_expr( \
__builtin_constant_p(expr), true, expr)); \
})
#endif
Note that the clang semantics of language extensions sometimes differ from GCC.I also like to use __auto_type very much:
#define var __auto_type
#define let __auto_type const
As in: #define m_max(a, b) \
__extension__ ({ \
let _a = (a); \
let _b = (b); \
_a > _b ? _a : _b; \
})