home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / c / 3214 < prev    next >
Encoding:
Text File  |  1992-12-16  |  2.2 KB  |  48 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!haven.umd.edu!decuac!pa.dec.com!engage.pko.dec.com!e2big.mko.dec.com!jrdzzz.jrd.dec.com!jit533.jit.dec.com!diamond
  3. From: diamond@jit533.jit.dec.com (Norman Diamond)
  4. Subject: Re: Is INT_MAX<<1 defined?
  5. Message-ID: <BzBwB8.I8z@jrd.dec.com>
  6. Sender: usenet@jrd.dec.com (USENET News System)
  7. Nntp-Posting-Host: jit533.jit.dec.com
  8. Reply-To: diamond@jit.dec.com (Norman Diamond)
  9. Organization: Digital Equipment Corporation Japan , Tokyo
  10. References: <1992Dec8.1 <Bz35no.J6M@jrd.dec.com> <8322@charon.cwi.nl> <1992Dec15.142103.49328@news.th-darmstadt.de>
  11. Date: Wed, 16 Dec 1992 01:33:08 GMT
  12. Lines: 34
  13.  
  14. In article <1992Dec15.142103.49328@news.th-darmstadt.de> wallmann@backus.pu.informatik.th-darmstadt.de (Natuerlich!) writes:
  15. >What I expect to happen in expressions like these:   INT_MAX << 1
  16. >is that the compiler behaves as if it were ultralame.
  17.  
  18. K&R defined C to be ultralame (as a replacement for assembly language),
  19. except that optimizations could range from ultrlame to (sometimes) unsafe.
  20. That's somewhat a different language from what we're dealing with now.
  21.  
  22. >It acts as if it doesn't precompute at compiletime but rather computes the
  23. >result at runtime.
  24.  
  25. In both K&R-1 and in ANSI/ISO C, it doesn't matter if this gets precomputed
  26. or not.  The execution of the program can't distinguish.  This entire
  27. discussion has not been trying to distinguish such a point.
  28.  
  29. >So that in fact the default type for INT_MAX is signed int (since there
  30. >isn't an U or an L anywhere) and the shifting operation operates on a
  31. >signed int on that system.
  32.  
  33. INT_MAX is always signed int, for the reason you gave.  The word "default"
  34. is meaningless here.  The shift operation operates on a signed int.
  35.  
  36. >If you want portability you write  (long) INT_MAX * 2 (or somesuch).
  37.  
  38. If you want portability you don't try to compute  INT_MAX << 1  in the
  39. first place.  This is what the entire discussion has been about.
  40.  
  41. Incidentally, (long) INT_MAX * 2 also isn't portable.  For example, int
  42. and long might both be 96 bits, and multiplying by 2 might overflow.
  43. But in this discussion, no one's been trying to get a long out of this.
  44. --
  45. Norman Diamond       diamond@jit081.enet.dec.com
  46. If this were the company's opinion, I wouldn't be allowed to post it.
  47. "It's been a lovely recession."
  48.