r- r-value vs l-value?

B

Ben C

Arrays don't have copy or assignment semantics, structures do. To
return something by value, you have to copy it. So it does make sense
to be able to return a structure and not an array.

Yes, exactly, the two things go hand-in-hand.

I had a look on Google and found that this has been discussed here
before. Structure assignment, and the possibility of passing and
returning struct instances was a "recent extension" in 1978. In K&R C
you had to memcpy your instances, or do memberwise assignment.

http://tinyurl.com/p635q
But you can assign to one, so it is consistent to be able to return one.

That part's consistent, but structure returning _does_ give rise to an
inconsistency: a struct instance returned from a function is by
(standard) definition an rvalue, even though it's an object. Some
compilers let you assign to it anyway. And it is I think the only way to
contrive an rvalue that's "the result of the [] operator", in the
example we just saw from the previous poster.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top