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

From: Bob Lied <lied AT lucent DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf bug ???
Date: Fri, 05 Jun 1998 15:34:29 -0500
Organization: Lucent Technologies
Lines: 10
Message-ID: <35785655.74D7EAD3@lucent.com>
References: <35784752 DOT B7BF8C31 AT hamburg DOT netsurf DOT de>
NNTP-Posting-Host: il0015lied1.ih.lucent.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>     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?

The solution is, "Don't do that."  The order of parameter
evaluation is compiler-dependent, and the order of applying
multiple post-increments is compiler-dependent. Depending on
the compiler, you could also get "1 1 2", "1 2 3", or "3 3 3".
Be less clever, it's easier for the compiler and the reader.

- Raw text -


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