Bug 77493 - cout output is out of order
cout output is out of order
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
8.0
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-11-07 17:42 EST by Paisa Seeluangsawat
Modified: 2007-04-18 12:48 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-11-07 17:42:28 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Paisa Seeluangsawat 2002-11-07 17:42:22 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830

Description of problem:
With default installation of Redhat 8.0  "gcc version 3.2 20020903 (Red Hat
Linux 8.0 3.2-7)", the code attached prints "21" in stead of "12"


Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. g++ a.cc
2. ./a.out


Actual Results:  "21"

Expected Results:  "12"

Additional info:

// ---- a.cc -----------------

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
  vector<int> v(5);
  for (int i=0; i<5; i++)  v[i]=i;
  vector<int>::iterator i= find(v.begin(), v.end(), 1);
  cout << (*i++) << (*i++) << endl;  
  // should print "12", but I got "21"
  return 0;
}
Comment 1 Jakub Jelinek 2002-11-07 18:16:28 EST
No, it is correct. When calling ostream::operator<<(int) there is no sequence
point between evaluation of ostream (together with the other operator<<(int))
and i++. Use at most one ++ or -- between each two sequence points to avoid this.

Note You need to log in before you can comment on or make changes to this bug.