Bugzilla (bugzilla.redhat.com) will be under maintenance for infrastructure upgrades and will not be available on July 31st between 12:30 AM - 05:30 AM UTC. We appreciate your understanding and patience. You can follow status.redhat.com for details.
Bug 77493 - cout output is out of order
Summary: cout output is out of order
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 8.0
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2002-11-07 22:42 UTC by Paisa Seeluangsawat
Modified: 2007-04-18 16:48 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2002-11-07 22:42:28 UTC

Attachments (Terms of Use)

Description Paisa Seeluangsawat 2002-11-07 22:42:22 UTC
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:

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

Actual Results:  "21"

Expected Results:  "12"

Additional info:

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

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 23:16:28 UTC
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.