is it undefined behaviour?
From: Daniel Schüle (uval_at_rz.uni-karlsruhe.de)
Date: 03/30/05
- Next message: Daniel Schüle: "Re: is it undefined behaviour?"
- Previous message: Victor Bazarov: "Re: Is this valid ISO C++?"
- Next in thread: Daniel Schüle: "Re: is it undefined behaviour?"
- Reply: Daniel Schüle: "Re: is it undefined behaviour?"
- Reply: Victor Bazarov: "Re: is it undefined behaviour?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 30 Mar 2005 03:16:04 +0200
Hi all!
given the following code
#include <iostream>
using std::cout;
using std::endl;
struct X
{
X & foo(int x){ cout << x << endl; return *this; }
};
void bad(int x, int y)
{
cout << x << '\t' << y << endl;
}
int main()
{
int a = 1, b = 2, c = 3; // 1
cout.operator <<(a * b).operator <<(b * c).operator <<((a = 0, c = 0));
a = 1, b = 2, c = 3;
X x;
x.foo(a).foo(b).foo(c); // 2
a = 1, b = 2;
bad(a * b, a=0); // 3
return 0;
}
Is it safe to assume that 1 and 2 will produce on every C++
implementation the same output (no undefined behaviour here)?
Or may C++ Compiler compute all the values in () first (as it may do in
bad), and then invoke function foo?
thx in advance
-Daniel
- Next message: Daniel Schüle: "Re: is it undefined behaviour?"
- Previous message: Victor Bazarov: "Re: Is this valid ISO C++?"
- Next in thread: Daniel Schüle: "Re: is it undefined behaviour?"
- Reply: Daniel Schüle: "Re: is it undefined behaviour?"
- Reply: Victor Bazarov: "Re: is it undefined behaviour?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|