delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/05/16:32:56

Message-Id: <m0yi394-000S3xC@inti.gov.ar>
Comments: Authenticated sender is <salvador AT natacha DOT inti DOT gov DOT ar>
From: "Salvador Eduardo Tropea (SET)" <salvador AT inti DOT gov DOT ar>
Organization: INTI
To: Dennis Voss <dennis DOT voss AT hamburg DOT netsurf DOT de>, djgpp AT delorie DOT com
Date: Fri, 5 Jun 1998 17:34:48 +0000
MIME-Version: 1.0
Subject: Re: printf bug ???
In-reply-to: <35784752.B7BF8C31@hamburg.netsurf.de>

Dennis Voss <dennis DOT voss AT hamburg DOT netsurf DOT de> wrote:
> I just wrote this little program:
> #include <stdio.h>
> 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019