Sujet : Re: Top 10 most common hard skills listed on resumes...
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 10. Sep 2024, 21:05:20
Autres entêtes
Organisation : None to speak of
Message-ID : <87wmjjz33z.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
Ben Bacarisse <
ben@bsb.me.uk> writes:
Bart <bc@freeuk.com> writes:
On 08/09/2024 17:44, Bart wrote:
On 08/09/2024 16:39, Ben Bacarisse wrote:
...]
I can think of at least one expression form for X that contradicts this
claim.
Example?
>
Nothing here either.
>
f().m where f returns a struct.
"A postfix expression followed by the . operator and an identifier
designates a member of a structure or union object. The value is that of
the named member, and is an lvalue if the first expression is an
lvalue."
A function call is not an lvalue, so f().m is not an lvalue.
But if the member is an array, then f().a[i] is an lvalue referring to
an object with automatic storage duration and *temporary lifetime* (a
concept introduced in C11). But modifying such an object has undefined
behavior. (The array itself can't be on the LHS of an assignment.)
For example:
struct foo { int arr[10]; };
struct foo func(void) {
struct foo result = { 0 };
return result;
}
int main(void) {
func().arr[0] = 42; // undefined behavior
}
A function call is not an lvalue (it yields a value but does not
designate an object), but if the result is a struct or union that has a
member of array type then that array needs to be treated as an lvalue
for indexing to work. (Prior to C11, the standard implicitly assumed
that an expression of array type can only be an lvalue. This left a
hole in the special case of an array member of a struct or union
returned from a function. C11 invented "temporary lifetime" to deal
with this.)
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */