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

From: Blaine Hodge <bhodge AT gpu DOT srv DOT ualberta DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf bug ???
Date: Fri, 05 Jun 1998 14:05:30 -0600
Organization: University of Alberta
Lines: 27
Message-ID: <35784F8A.AB5D79CC@gpu.srv.ualberta.ca>
References: <Pine DOT GSO DOT 3 DOT 96 DOT 980605144528 DOT 10548A-100000 AT bert DOT eecs DOT uic DOT edu>
NNTP-Posting-Host: async15-3.remote.ualberta.ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> > #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.
> 
> The reason you got 3 2 1 is because some compilers parse from right to
> left (I suppose DJGPP does that) and you should never do such statement,
> it's a bad programming practice and can cause unstable results.

Yup.  This is the correct response you should get.  Arguements are
popped onto the stack right to left for function calls.

>  > I also
> compiled this with
> Visual C++ 5 and the output was "1 1 1". > Can anyone help me solve this?

Then its VC at fault (gee, imagine that), sounds like its evaluating it
using the Pascal calling method, left to right, and not C/C++, right to
left.

-- 
Blaine Hodge
E-Mail: bhodge AT gpu DOT srv DOT ualberta DOT ca
WWW: http://www.ualberta.ca/~bhodge/

- Raw text -


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