Re: [Dev-C++] Problem with 'std::cout' (?)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: matheus r. <mfr...@gm...> - 2007-10-04 14:43:00
|
The statement evaluation happens from right to the left, like all
others. But the ostream operator << acts like a stack. You evaluate
expression from right, push. Then at the end, everything added is
popped.
So basically, you push 512, 256, 128. Then you pop 128, 256, 512.
2007/10/4, Franco Brancaccio <fbr...@gm...>:
> Dear Friends,
>
> I observed an irregular (I think) comportment of 'std::cout'
> reproduced by the simple test code below:
>
>
> #include <iostream>
> using namespace std;
>
>
> int myFunc(); // simple test function prototype
>
>
> // test program
> int main()
> {
> cout << myFunc() << endl // this block results
> << myFunc() << endl // in an inverted
> << myFunc() << endl << endl; // console output
>
> cout << myFunc() << endl; // this block results
> cout << myFunc() << endl; // in a correct
> cout << myFunc() << endl << endl; // console output
>
> system("PAUSE");
> return 0;
> }
>
>
> // simple test function implementation
> int myFunc()
> {
> static int i = 1024;
> i /= 2;
> return i;
> }
>
>
> The console output for this code is:
>
>
> 128
> 256
> 512
>
> 64
> 32
> 16
>
> Press any key to continue...
>
>
> The questions:
> The two 'cout' blocks act in a different manner! (?)
> Why the first chained block results in an inverted output?
> Does not the insert operator '<<' act from left to right?
>
> Obs.: I'm using
> Dev-C++ 4.9.9.2 ,
> Win XP 5.1,
> g++ (1/29/2005).
>
>
> TIA,
> Franco Brancaccio
> fbr...@gm...
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
|