Mail Archives: djgpp/1998/06/05/16:32:56
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 -