Jens Gustedt
7/2/2011 7:52:00 AM
Am 28.06.2011 21:59, schrieb jacob navia:
> Le 28/06/11 21:43, Ian Collins a écrit :
>> foo( n++ ); // What is the resulting value of n?
> I just do not see what is the problem but very probably it is my fault.
The problem is that you can't get by any means close to the behavior
of C++. In C++ many of the standard operators return lvalues where
they return rvalues in C.
For the example, instead of postfix ++ use
foo(++n);
This would compile in C++ (for foo taking a reference) and give the
user about what (s)he expects, since (in C++) in contrast to n++
(which returns an rvalue) ++n evaluates to an lvalue that represents
the same object as n.
A simple rule that just implicitly creates lvalues from rvalues when
passed to a function with references would have surprising effects
for the programmer.
Introducing references into C without discussing the types of all
standard operators (in terms of rvalue or lvalue) and without
discussing if functions would be allowed to return lvalues makes not
much sense to me.
Jens