Eric Blake wrote:
/* The maximum and minimum values for the integer type T. These
macros have undefined behavior if T is signed and has padding bits.
If this is a problem for you, please let us know how to fix it for
your host. */
#define TYPE_MINIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) 0 \
: TYPE_SIGNED_MAGNITUDE (t) \
? ~ (t) 0 \
: ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
#define TYPE_MAXIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) -1 \
: ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
I must admit I don't know what an integer with padding bits would look
like. Can someone check what the C standard has to say about the
bit-not operator? According to what GCC currently does, there is no
integer overflow anywhere in this code: bit-not expressions never
overflow, and a integer shift of -1 by (sizeof - 1) bits does not change
the sign, and therefore doesn't overflow.
Even with -Woverflow, GCC does not warn when these macros are used for
type "int".
Bernd