Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: Dennis Voss , djgpp AT delorie DOT com Date: Fri, 5 Jun 1998 17:34:48 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: printf bug ??? In-reply-to: <35784752.B7BF8C31@hamburg.netsurf.de> Precedence: bulk Dennis Voss wrote: > I just wrote this little program: > #include > void main(void) > { > int i = 1; > printf("%d %d %d", i, i++, i++); > } > Using DJGPP I got the output "3 2 1" which is wrong. > I also compiled this with Visual C++ 5 and the output was "1 1 1". > Can anyone help me solve this? I don't know what ANSI standard says, but as I understand the post increment operator must increment after use so the right-most value will be 1 because is the value of i before the printf line, then gcc push the value to the stack. Now i *was used* and hence gcc applies the post increment so now i=2, then gcc pushes 2 and increments so you get 2 and 3. SET ------------------------------------ 0 -------------------------------- Visit my home page: http://set-soft.home.ml.org/ or http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org ICQ: 2951574 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013