Article View: comp.std.c
Article #3029Re: Is INT_MAX<<1 defined?
From: Norman Diamond
Date: Wed, 16 Dec 1992 01:33
Date: Wed, 16 Dec 1992 01:33
34 lines
2344 bytes
2344 bytes
In article <1992Dec15.142103.49328@news.th-darmstadt.de> wallmann@backus.pu.informatik.th-darmstadt.de (Natuerlich!) writes: >What I expect to happen in expressions like these: INT_MAX << 1 >is that the compiler behaves as if it were ultralame. K&R defined C to be ultralame (as a replacement for assembly language), except that optimizations could range from ultrlame to (sometimes) unsafe. That's somewhat a different language from what we're dealing with now. >It acts as if it doesn't precompute at compiletime but rather computes the >result at runtime. In both K&R-1 and in ANSI/ISO C, it doesn't matter if this gets precomputed or not. The execution of the program can't distinguish. This entire discussion has not been trying to distinguish such a point. >So that in fact the default type for INT_MAX is signed int (since there >isn't an U or an L anywhere) and the shifting operation operates on a >signed int on that system. INT_MAX is always signed int, for the reason you gave. The word "default" is meaningless here. The shift operation operates on a signed int. >If you want portability you write (long) INT_MAX * 2 (or somesuch). If you want portability you don't try to compute INT_MAX << 1 in the first place. This is what the entire discussion has been about. Incidentally, (long) INT_MAX * 2 also isn't portable. For example, int and long might both be 96 bits, and multiplying by 2 might overflow. But in this discussion, no one's been trying to get a long out of this. -- Norman Diamond diamond@jit081.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it. "It's been a lovely recession."
Technical Details
Message-ID:
<BzBwB8.I8z@jrd.dec.com>Path:
arc1-ca.pugleaf.net!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!diamondReferences:
<1992Dec8.1 <Bz35no.J6M@jrd.dec.com> <8322@charon.cwi.nl> <1992Dec15.142103.49328@news.th-darmstadt.de>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!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 From: diamond@jit533.jit.dec.com (Norman Diamond) Subject: Re: Is INT_MAX<<1 defined? Message-ID: <BzBwB8.I8z@jrd.dec.com> Sender: usenet@jrd.dec.com (USENET News System) Nntp-Posting-Host: jit533.jit.dec.com Reply-To: diamond@jit.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo References: <1992Dec8.1 <Bz35no.J6M@jrd.dec.com> <8322@charon.cwi.nl> <1992Dec15.142103.49328@news.th-darmstadt.de> Date: Wed, 16 Dec 1992 01:33:08 GMT Lines: 34