This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
The order of calling functions and << <<
- To: egcs at cygnus dot com (egcs at cygnus dot com)
- Subject: The order of calling functions and << <<
- From: Carlo Wood <carlo at runaway dot xs4all dot nl>
- Date: Mon, 7 Dec 1998 17:28:49 +0100 (CET)
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>