Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!dciem!nrcaer!cognos!brianc From: brianc@cognos.uucp (Brian Campbell) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: What's Wrong here? Message-ID: <1930@cognos.UUCP> Date: Thu, 3-Dec-87 13:39:00 EST Article-I.D.: cognos.1930 Posted: Thu Dec 3 13:39:00 1987 Date-Received: Sun, 6-Dec-87 18:36:19 EST References: <278@westmark.UUCP> <6755@brl-smoke.ARPA> Reply-To: brianc@cognos.UUCP (Brian Campbell) Organization: Cognos Incorporated, Ottawa, Canada Lines: 25 Xref: dciem comp.lang.c:5232 comp.sys.ibm.pc:8877 In article <6755@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) writes: ! In article <278@westmark.UUCP> dave@westmark.UUCP (Dave Levenson) writes: ! > long n; ! > n = (1 << 31) -1; ! ! Try changing the first "1" to "1L"; otherwise the whole expression ! is evaluated using (int)s, not (long)s, before the value is assigned. ! If (int) has 16 bits, the left-shift overflows and a variety of ! results are possible, including the one you reported. ! ! By the way, you're treading on thin ice anyway, since (1L << 31) is ! the most-negative 2's complement integer, so subtracting 1 from it ! is yet another undefined operation. I'm not sure what this code is ! trying to accomplish, but consider using ! unsigned long n; ! n = ((unsigned long)1 << 31) - 1; I don't think this is good advice. Unless the assigment is supposed to be setting all bits except the 32nd, I think Dave should be assigning from a define. The LONG_MAX defined in sounds ideal, although its defined in and is called MAXLONG on my machine ... -- Brian Campbell uucp: decvax!utzoo!dciem!nrcaer!cognos!brianc Cognos Incorporated mail: POB 9707, 3755 Riverside Drive, Ottawa, K1G 3Z4 (613) 738-1440 fido: (613) 731-2945 300/1200, sysop@1:163/8