4 ms·
Apparently the static_assert trick doesn't work with GCC, it just compiles it with a warning if it's not a constant expression: warning: expression in static
by listeria 1y ago
Apparently the static_assert trick doesn't work with GCC, it just compiles it with a warning if it's not a constant expression:
warning: expression in static assertion is not an integer constant expression [-Wpedantic]
Instead you can use the sizeof + compound literal with array type, use the comma operator to preserve the type of the expression and cast the result of sizeof to void to suppress the warning:
#define C(x) ( (void)sizeof( (char [(int)(x) || 1]){0} ), (x) )
The only problem is that it doesn't support floating point expressions