#262 Evaluation order of assignments

Feature_requests
closed-invalid
Danny Smith
gcc (462)
2014-08-15
2003-01-18
Pete-ohki
No

I've noticed that Mingw evaluates all variables on the
right-hand side first before passing the values to the left-
hand. In a statment like

cout << *ForwardIterator << *(++ForwardIterator);

the pointer of ForwardIterator is advanced by one before
the statement is evaluated and sent to the output
stream. That means the same value is sent; if
ForwardIterator was initially on 0, the value at 1 is sent
to cout both times.

I'm trying to use Mingw to do my G++ projects, and with
G++, I've gotten use to having such statements
evaluated as it appears in order such that the above
statement would send the values at 0 and then at 1 to
cout.
-----Is there a way to set Mingw to evaluate assignment
statements in a left-to-right order?

Patrick Leung

Discussion

  • Luke Dunstan
    Luke Dunstan
    2003-01-20

    Logged In: YES
    user_id=30442

    In case you didn't see the reply that was posted to the
    mailing list, see here:

    http://groups.google.com/groups?selm=78o1ma%24nr4%
    241%40nnrp1.dejanews.com

    Basically the answer is that the order of evaluation of
    expressions within a statement is undefined by the language,
    so your code should never rely on it. Simply use two separate
    statements.

     
  • Luke Dunstan
    Luke Dunstan
    2003-01-20

    • status: open --> closed-invalid