Path: utzoo!attcan!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond From: diamond@csl.sony.JUNET (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: Turbo C bug ! Message-ID: <10010@diamond.csl.sony.JUNET> Date: 24 Jan 89 00:41:38 GMT References: Distribution: comp Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan Lines: 41 In article , pk-tle@sics.se (Tommy Levitte) writes: > #define X 240 > #define Y 240 > #define Z ((X)*(Y)) > > void fn(unsigned long i) > { > printf("%ld %ul\n",i,i) > } > > main() > { > fn(Z); > } > Running this gave me a nice surprise: > -7936 2147475712 Looks like they FIXED a bug in the earlier version. 240 is an int, 240 * 240 is the int -7936, convert it to unsigned long for i and get 2147475712. Tell printf that it's signed long and it changes back to -7936; tell printf that it's unsigned long and you get 2147475712. > But if I change fn(Z) with fn(57600), it gives me the right numbers: > 57600 57600 57600 is a long. Convert it to unsigned long for i and get 57600. The rest is obvious. > Fix : Put an L at the end of 240 !!!! Yes, that is one way to fix your own bug. [Now to fix the bug in inews that requires more of my text than yours] [again] -- Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net) The above opinions are my own. | Why are programmers criticized for If they're also your opinions, | re-inventing the wheel, when car you're infringing my copyright. | manufacturers are praised for it?