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]

Re: The order of calling functions and << <<


On Mon, 7 Dec 1998, Joe Buck wrote:

> The standard says that the behavior of the above program is undefined,
> because the order of evaluation of arguments to a function call is unspecified.
> 
> You have written
> 
> operator<<(operator<<(operator<<(operator<<(cout, "1"),foo()),"4"),endl);
> 
> The source of the undefined behavior is that in
> 
> operator<<(operator<<(cout, "1"), foo());
> 
> the compiler is free to either do operator<<(cout,"1") first or to call
> foo() first.  This means that you could get "124\n" or "214\n".

Um! I don't think that is right either. The foo() function prints 2 *and*
returns an integer - 3 in this case. So I believe what would happen with
the line:

>   cout << "1" << foo() << "4" << endl;

would become

1234

This makes sense. Or not? Hmm. Lemme try this out. 

Cheers,
Alex.

---
 /\_/\  Legalise cannabis now! 
( o.o ) Grow some cannabis today! 
 > ^ <  Peace, Love, Unity and Respect to all.

Check out http://www.tahallah.demon.co.uk
Linux lo-pc3035a 2.1.130 #10 Mon Nov 30 10:49:50 EST 1998
One Intel Pentium 166MHz processor, 66.36 total bogomips, 16M RAM
System library 5.4.44



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