home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / apollo / 3158 < prev    next >
Encoding:
Internet Message Format  |  1992-07-30  |  1.5 KB

  1. From: mev@hpfcso.FC.HP.COM (Mike Vermeulen)
  2. Date: Thu, 30 Jul 1992 14:48:31 GMT
  3. Subject: Re: an annoying bug in the C compiler ...
  4. Message-ID: <9330033@hpfcso.FC.HP.COM>
  5. Organization: Hewlett-Packard, Fort Collins, CO, USA
  6. Path: sparky!uunet!walter!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hplextra!hpfcso!mev
  7. Newsgroups: comp.sys.apollo
  8. References: <1992Jul29.102800.10843@usage.csd.unsw.OZ.AU>
  9. Lines: 27
  10.  
  11. The interpretation of the constant -2147483648 is one area that the ANSI C
  12. standard has subtlely changed from many existing implementations.
  13.  
  14. In the standard, there is no syntax for a negative constant, instead this is
  15. interpreted as a constant expression with a unary - operator over a positive
  16. constant.  Section 3.1.3.2 states that the type of an unsuffixed integer
  17. constant is the first of a list in which its value can be represented.
  18. This list is
  19.  
  20.    int, long int, unsigned long int
  21.  
  22. The positive value 2147483648 is one too large for the int or long int type,
  23. so it has type unsigned long int.  A unary - operator applied to an unsigned
  24. long int value of 0x8000000 results in the same bit pattern and has the type
  25. unsigned long int.
  26.  
  27. This is the reason for the behavior you are seeing.  It is also the reason
  28. header files (on Domain/OS and hp-ux) contain:
  29.  
  30.     #define INT_MIN (-2147483647-1)
  31.  
  32. My suggestion would be to alter your program to either use INT_MIN or a similar
  33. expression as above.
  34.  
  35. --mev
  36.  
  37. Disclaimer: Not an official response from Hewlett Packard
  38.