Sujet : Re: Regarding assignment to struct
De : noone (at) *nospam* noone.net (Andrey Tarasevich)
Groupes : comp.lang.cDate : 05. May 2025, 09:29:47
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vv9stv$2i8j$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On Mon 5/5/2025 1:12 AM, Michael S wrote:
According to my understanding, you are wrong.
Taking pointer of non-lvalue is UB, so anything compiler does is
conforming.
Er... What? What specifically do you mean by "taking pointers"?
The whole functionality of `[]` operator in C is based on pointers. This expression
(a = b).a[5]
is already doing your "taking pointers of non-lvalue" (if I understood you correctly) as part of array-to-pointer conversion. And no, it is not UB.
This is not UB either
struct S foo(void) { return (struct S) { 1, 2, 3 }; }
...
int *p;
p = &foo().a[2], printf("%d\n", *p);
So, what you are basing your "UB" claim on is not clear to me.
-- Best regards,Andrey