This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

The order of calling functions and << <<


The following compiler behaviour is different from gcc-2.7 if I remember well.

When I do:

#include <iostream>

int foo(void)
{
  cout << "2";
  return 3;
}

int main(void)
{
  cout << "1" << foo() << "4" << endl;
  return 0;
}

I expect to get "1234", but instead I get:

~/c++/tests>a.out
2134

The reason for this is that every variable is first
calculated, put on stack and only then the ostream operator<<()
are called...

Is this what was intended?  What does the ANSI/ISO C++ standard
say about this?  Is indeed

cout << "1";
cout << foo();

NOT equal to

cout << "1" << foo();

?

Please CC me as I am not on this list.

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]