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