In Computer Systems: a Programmer's Perspective:
Writing TMin in C In Figure 2.19 and in Problem 2.21, we carefully wrote the value of TMin32 as -2,147,483,647-1. Why not simply write it as either -2,147,483,648 or 0x80000000? Looking at the C header file limits.h, we see that they use a similar method as we have to write TMin32 and TMax32:
/* Minimum and maximum values a ‘signed int’ can hold. */ #define INT_MAX 2147483647 #define INT_MIN (-INT_MAX - 1)
Unfortunately, a curious interaction between the asymmetry of the two’s-complement representation and the conversion rules of C forces us to write TMin32 in this unusual way. Although understanding this issue requires us to delve into one of the murkier corners of the C language standards, it will help us appreciate some of the subtleties of integer data types and representations.
What is the "interaction between the asymmetry of the two’s-complement representation and the conversion rules of C"?
Why does it force us to write TMin32 i.e. INT_MIN in this unusual way?
User contributions licensed under CC BY-SA 3.0