GIVEN:
A type defined as TheValueT
that may be arbitrarily configured, e.g. as uint8_t
or int64_
. Let there be some code:
TheValueT x = ...;
... do something to 'x' ...
if( x < 0 ) {
/* Do something. */
}
PROBLEM:
It happens that if TheValueT
is defined as an unsigned type, the compiler complains about 'condition always true because of limited range of type ...'.
QUESTION:
How can the compiler warning be avoided whilst letting TheValueT
still be of arbitrary integer type? The solution should be applicable to the widest range of C compilers.