delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/09/08:46:36

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf bug ???
Date: Fri, 05 Jun 1998 18:36:11 -0700
Organization: Alcyone Systems
Lines: 27
Message-ID: <35789D0B.10612714@alcyone.com>
References: <35784752 DOT B7BF8C31 AT hamburg DOT netsurf DOT de>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Dennis Voss wrote:

>     printf("%d %d %d", i, i++, i++);
	...
> Using DJGPP I got the output "3 2 1" which is wrong.

Ask yourself this question:  Why is that wrong?

It is not wrong.

> I also compiled this with Visual C++ 5 and the output was "1 1 1".

Hint:  This is not wrong either.

> Can anyone help me solve this?

The answer is that an expression with side effects involving the same
lvalue multiple times are in general undefined.  Solution:  Don't do
that.

-- 
         Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                       Alcyone Systems / http://www.alcyone.com/max/
  San Jose, California, United States / icbm:+37.20.07/-121.53.38
                                     \
           She glanced at her watch / . . . It was 9:23.
                                   / James Clavell

- Raw text -


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