Re: reference type methods
On Jul 15, 1:37 pm, Ruben <ru...@www2.mrb rklyn.comwrote:
I think you're confusing things. An array is not a pointer,
that's certain. But an expression with an array type will
implicitly convert to a ponter. And since the [] is only
defined for pointers (not for arrays), that's what happens here.
See section 4.2 in the C++ standard for the array to pointer
conversion, and 5.2.1 for the definition of the [] operator (or
sections 6.3.2.1 and 6.5.2.1 respectively in the C standard).
Who said it was? But since the [] operator is not defined for
array types, the array converts to a pointer.
No. The expression x is an lvalue. It is used to initialize
the return value (which can be thought of as a hidden temporary
object), which involves an lvalue to rvalue conversion.
And of course, 10 is not an lvalue, but 10 isn't x.
Of course not. A function expression is an lvalue if and only
if its return type is a reference.
I think you really need a basic course in C/C++ expressions.
Lvalue-ness applies to expressions, not values. And because of
the lvalue to rvalue conversion, an expression which is an
lvalue can be used where ever an rvalue is required. (The
reverse is not true, of course.)
--
James Kanze (GABI Software) email:james.kan ze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Jul 15, 1:37 pm, Ruben <ru...@www2.mrb rklyn.comwrote:
On Tue, 15 Jul 2008 02:32:48 -0700, James Kanze wrote:
No. By definition, i[index] is *(i + index), and the
results of a dereference operator is always an lvalue.
There's no literal involve here at all.
results of a dereference operator is always an lvalue.
There's no literal involve here at all.
Can you show me that definition, because I've had a whole
other conversation in the comp.lang.c that was supported by
compiler output and the C FAQ that proved this to be untrue.
other conversation in the comp.lang.c that was supported by
compiler output and the C FAQ that proved this to be untrue.
that's certain. But an expression with an array type will
implicitly convert to a ponter. And since the [] is only
defined for pointers (not for arrays), that's what happens here.
See section 4.2 in the C++ standard for the array to pointer
conversion, and 5.2.1 for the definition of the [] operator (or
sections 6.3.2.1 and 6.5.2.1 respectively in the C standard).
An array object is not just a simple pointer. And when I've
worked with bearwolf cluster programming, this is explicitely
clear.
worked with bearwolf cluster programming, this is explicitely
clear.
array types, the array converts to a pointer.
With regard to the lvalue of a valuable's data,
your saying that
int x = 10;
retunr x;
that returns an lvalue? 10 is not an lvalue. So I've
confused. If this was true then I would be able to do with
confused. If this was true then I would be able to do with
the return value (which can be thought of as a hidden temporary
object), which involves an lvalue to rvalue conversion.
And of course, 10 is not an lvalue, but 10 isn't x.
int f(x);
f(x) = 5; //that can't be done
if its return type is a reference.
I think we are mixing up the data stored in variables from the
variables themselves.
variables themselves.
Lvalue-ness applies to expressions, not values. And because of
the lvalue to rvalue conversion, an expression which is an
lvalue can be used where ever an rvalue is required. (The
reverse is not true, of course.)
--
James Kanze (GABI Software) email:james.kan ze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Comment