I'm trying to build a simple SIGNOF
macro:
#define SIGNOF(a) ((a) < 0 ? -1 : 1)
If a
is negative it should return -1, otherwise 1. If a
is an unsigned type, it should always return 1 and the compiler can optimize away the negative code path.
However, GCC rightfully warns me that
error: comparison of unsigned expression in ‘< 0’ is always false [-Werror=type-limits]
29 | #define SIGNOF(a) ((a) < 0 ? -1 : 1)
But in this case I actually want this behavior. Is there any way to tell the compiler that this is intentional, similar to /* fall-though */
in a switch-case?