Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!bellcore!petrus!scherzo!allegra!princeton!orsvax1!pyrnj!caip!lll-crg!mordor!ut-sally!cyb-eng!bc From: bc@cyb-eng.UUCP (Bill Crews) Newsgroups: net.lang.c,net.micro,net.micro.pc Subject: Re: weird C behavior Message-ID: <796@cyb-eng.UUCP> Date: Wed, 2-Apr-86 19:30:40 EST Article-I.D.: cyb-eng.796 Posted: Wed Apr 2 19:30:40 1986 Date-Received: Sat, 5-Apr-86 07:03:35 EST References: <557@utastro.UUCP> Organization: Cyb Systems, Austin, TX Lines: 32 Xref: linus net.lang.c:7745 net.micro:12960 net.micro.pc:7332 > /* weird.c - demonstrate weird C behavior */ > /* Reference: Kernighan and Ritchie pp. 40-41 */ . . . > #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 > > ----------------------------------------------------------------------- > Ed Nather > Astronomy Dept, U of Texas @ Austin It seems to me that your compiler has done the right thing. Since 36864 cannot be represented as an int on your machine, it generated a positive long rather than a negative int. When i is extended to a long, the sign bit is extended, so the comparison fails, as it should. The only reason you got -28672 for BIG instead of nulls is because your machine has backwards byte order. -- - bc - ..!{seismo,topaz,gatech,nbires,ihnp4}!ut-sally!cyb-eng!bc (512) 835-2266