3 ms·
> #define MY_ASSERT(expr) sizeof(expr) sizeof accepts a type or an expression as its input, so it would compile successfully if expr were a type but not a vali
by jcranmer 7y ago
> #define MY_ASSERT(expr) sizeof(expr)
sizeof accepts a type or an expression as its input, so it would compile successfully if expr were a type but not a valid expression (say, int).
- edflsafoiewq 7y agoYou could do sizeof((expr)?1:2) instead, which would also force expr to be contextually convertible to a bool.
- pandaman 7y agosizeof((expr)) would suffice to filter out types.