Topic: Strange behavior of struct return values


Author: aitken@halcyon.com (William E. Aitken)
Date: 1999/06/07
Raw View
Consider the following declarations.

struct S1 {
        int x;
        int rgx[5];
};

S1 Mumble();

Does it seem odd to anyone else that
 Mumble().x = 5;
is illegal, but
 Mumble().rgx[0] = 5;
is legal?  The former is illegal because Mumble() is not an lvalue, so
neither is Mumble().x.  The latter is legal because Mumble().rgx can
be implicitly converted to int*, and because pointer dereference (*)
always yields an lvalue. [Recall a[b] is definitionally equivalent to
*(a + b) for built-in types.]
--
William E. Aitken        | Formal verification is the
email: aitken@halcyon.com                   |  future of computer science ---
Snail: 8500 148th Ave NE #H1026 Redmond WA  | Always has been, always will be.
===============================================================================
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]