I'm sory but I don't understand the difference between a lvalue-arrays
and a rvalue-arrays?
Are you saying that
struct A
{
char arr[N];
};
and
char arr2[N];
are conceptually different?
I don't understand many facets of lvalue and rvalue either but one
obvious difference is that your struct is only a declaration of a type
while your arr2 is the definition of an object. If you define a
struct A named x, there is still one obvious difference. Passing x to
a function will result in a complete copy of the array arr being
passed to the function. Passing arr2 to a similar function will
result in the address of the array being passed. In the first case,
updates to array elements are local to the called function. In the
second, updates are made directly to the array in the calling
function.
I know all of this details but I have some difficulties with this
notion of lvalues/rvalues. In all case a table is nothing more than a
data storage so what's the difference that affects the "l/r
valuability" (oh my god, my poor English)?.
An lvalue is an expression that designates an object.
The difference here is that the value returned by a function isn't
(considered to be) an object, even if it's a structure.
If a function returns an array -- well, a function *can't* return an
array, so instead it will typically return a pointer to the first
element of an array. And that pointer has to point to an object
that's been created in some other manner (a declared object, a
malloc()ed object, a string literal, a piece of some larger object,
etc.).
If a function returns a structure, it just returns the *value* of that
structure; conceptually at least, there's no object that holds that
value and whose address you could take. (In practice, there's likely
to be a struct object somewhere in memory, created by the code
generated by the compiler, but that "object" isn't visible as an
object to C code, so it doesn't count.)
If the structure contains an array, then you have an array that's not
an object; the change in C99 allows indexing into that array.
As far as I know, this case (a function returning a structure that
contains an array) is the only case where you can have an array
expression without a corresponding array object.
--
Keith Thompson (The_Other_Keith) (e-mail address removed) <
http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"