Xref: utzoo comp.lang.c:35542 comp.os.msdos.programmer:2971 Path: utzoo!attcan!uunet!fernwood!portal!cup.portal.com!ekalenda From: ekalenda@cup.portal.com (Edward John Kalenda) Newsgroups: comp.lang.c,comp.os.msdos.programmer Subject: Re: Possible C compiler bug on 8086 machines Message-ID: <37914@cup.portal.com> Date: 12 Jan 91 08:52:17 GMT References: <3577@bruce.cs.monash.OZ.AU> Organization: The Portal System (TM) Lines: 29 > The following program demonstrates a printf that doesn't seem to work > properly when compiled using a variety of C compilers for an 8086 machine. > The program is as follows: > > #include > main() > { > int x,y; > x = 65536/512; > y = 512; > printf("This works : %d, %d\n",x,y); > printf("This doesn't work : %d, %d\n",65536/512,512); > } > And here is a sample output: > This works : 128, 512 > This doesn't work : 128, 0 > > Does anyone have any idea why? > Is this a problem with my machine or the printf routine? The problem is that 65536/512 results in a LONG being pushed on the stack so the send %d gets the high word of the long, which is zero. The reason it works in the first case is that the long result is converted to an int when assigned to the int x. I use MSC 6.0 with /X4 to catch oddities like this at compile time. Most UNIX programmers run into this when moving from the 32 bit machines to DOS. Ed ekalenda@cup.portal.com