Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.lang.c,net.micro,net.micro.pc Subject: Re: weird C behavior Message-ID: <324@hadron.UUCP> Date: Sat, 22-Mar-86 04:11:16 EST Article-I.D.: hadron.324 Posted: Sat Mar 22 04:11:16 1986 Date-Received: Tue, 25-Mar-86 03:23:54 EST References: <557@utastro.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 26 Keywords: strange, opaque, odd Xref: watmath net.lang.c:8240 net.micro:14105 net.micro.pc:7514 Summary: Are you mixing 16 & 32? In article <557@utastro.UUCP> nather@utastro.UUCP (Ed Nather) writes: >/* weird.c - demonstrate weird C behavior */ >/* Reference: Kernighan and Ritchie pp. 40-41 */ >#include >#define BIG 36864 >main() >{ >int i; > >i = BIG; >if(i == BIG) > printf("Equality found: i = %d, BIG = %d\n", i, BIG); >else > printf("Equality NOT found: i = %d, BIG = %d\n", i, BIG); >} >Equality NOT found: i = -28672, BIG = -28672 Check the code produced by your compiler. Could you be mixing 16- and 32-bit operations? I.e., could the compiler be moving the BIG word into 16-bit i (making it a negative number), then (finding that BIG is > 32767) upgrading both to (long) before the compare? Check and see. You don't say what machine or C you used, so we have no way of telling. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}