This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: The order of calling functions and << <<
- To: Joe Buck <jbuck at Synopsys dot COM>
- Subject: Re: The order of calling functions and << <<
- From: Alex Buell <alex dot buell at tahallah dot demon dot co dot uk>
- Date: Mon, 7 Dec 1998 12:58:36 -0500 (EST)
- cc: Carlo Wood <carlo at runaway dot xs4all dot nl>, egcs at cygnus dot com
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