Friday, August 27, 2010

ANSI C vs ISO C++

Q:
int x = 0;
int y = 0;
(1 ? x : y) = 4;



A:
This is not legal in ANSI C:
6.5.15/4
If an attempt is made to modify the result of a conditional operator
or to access it after the next sequence point, the behavior is undefined.


However, in C++ we have:
5.16/4
If the second and third operands are lvalues and have the same type,
the result is of that type and is an lvalue.
5.16/5
Otherwise, the result is an rvalue.


via linkedin.com, cpptrivia.blogspot.com

No comments:

Post a Comment