Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: What's Wrong here? Message-ID: <6755@brl-smoke.ARPA> Date: Sat, 28-Nov-87 20:18:08 EST Article-I.D.: brl-smok.6755 Posted: Sat Nov 28 20:18:08 1987 Date-Received: Tue, 1-Dec-87 01:49:10 EST References: <278@westmark.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 15 Xref: mnetor comp.lang.c:5621 comp.sys.ibm.pc:10586 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;