-6

There is a problem which makes me very puzzled today.When I read the APPENDIX B, B11, the content of of The C Programming Language , I found that it's saying the INT_MIN is -32767, and INT_MIN is also 32767. But, in fact, The -INT_MAX should be greater than INT_MAX by 1, shouldn't it? And I have tried to find the answer on the net, and found something information about saying that the INT_MAX has been defined to the (-INT_MAX - 1), and something other information is same to the TCPL. In my program,the print of the INT_MIN is all -2147483648 and greater than -INT_MAX by 1; So, does there have something wrong in The C Programming Language?

#include <stdio.h>
#include <limits.h>
int main()
{
    signed int i1, i11;     
    printf("signed int:\n%d, %d\n", INT_MIN, INT_MAX);
    i1 = i11 = 6;:
    for(;i1 <= i11; --i1);
    printf("%d, ", ++i1);
    for(;i1 >= i11; ++i1);
    printf("%d\n", --i1);
    return 0;
}  
xy36
  • 315
  • 1
  • 11
Harukaze
  • 2,239
  • 2
  • 10
  • 7

1 Answers1

1

You missed this sentence before the definitions:

The minimum magnitudes shown shall be replaced by implementation-defined magnitudes with the same sign

so those defines are only minimums.

"But, in fact, The -INT_MAX should be greater than INT_MAX by 1, shouldn't it? "

That is a property of a 2-complement architecture. But it isn't a property of C, which can be used on other architectures as well.

Per Johansson
  • 6,697
  • 27
  • 34
  • 2's complement is not an _architecture_, but an encoding, thus a human interpretation, to represent signed integer values. FYI: I't major advantage is that add/sub don't need to handle the sign explicitly, i.e. they don't have to care about the sign. Also hardware overflow-detection is very simple to implement (the internal overflow flag is just a courtesy of the CPU to help detecting such conditions). Other operations are more complicated, thus e.g. IEEE floating point does not use it. – too honest for this site Feb 11 '16 at 13:52
  • Oh,I have got it. Thank you very much! – Harukaze Feb 12 '16 at 10:33