Mail Archives: djgpp/1998/06/06/02:15:24

From: "Martin Ambuhl" <mambuhl AT tiac DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf bug ???
Date: Sat, 6 Jun 1998 02:15:34 -0400
Organization: Nocturnal Aviation
Lines: 37
Message-ID: <6laq8j$>
References: <35784752 DOT B7BF8C31 AT hamburg DOT netsurf DOT de>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Dennis Voss wrote in message <35784752 DOT B7BF8C31 AT hamburg DOT netsurf DOT de>...
:Hi there,
: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?
When you violate the standard, and produce code that
by definition has undefined behavior, expect to get
undefined behavior.
From 6.3 of the standard:
"Between the previous and next sequence point, an object
shall have its stored value modified at most one be the
evaluation of an expression.  Furthermore, the prior value shall
be accessed only to determine the value to be stored."
and from
"The order of evaluation of the function designator, the arguments,
and subexpression within the argument is unspecified, but there is
a sequence point before the actual call."

If you don't understand just how badly you violated the standard,
get the comp.lang.c FAQ from
:Dennis Voss

- Raw text -

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