Hacker News new | ask | show | jobs
by jcranmer 2432 days 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).

1 comments

You could do sizeof((expr)?1:2) instead, which would also force expr to be contextually convertible to a bool.
sizeof((expr)) would suffice to filter out types.