Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Regarding assignment to struct Date: Mon, 05 May 2025 01:34:16 -0700 Organization: None to speak of Lines: 31 Message-ID: <87o6w7h2wn.fsf@nosuchdomain.example.com> References: <86plgo7ahu.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Mon, 05 May 2025 10:34:17 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ce0368853eba606cbaed4ff885db219e"; logging-data="99403"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9PvjgH5sC9eFqyikohhZC" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:PsnhPUBlqirkm3KEO8+8Mn9K8bk= sha1:03VlHcawcNRkmkz3Sqa8Vx4lpwo= Andrey Tarasevich writes: [...] > #include > > struct S { int a[10]; }; > > int main() > { > struct S a, b = { 0 }; > int *pa, *pb, *pc; > > pa = &a.a[5]; > pb = &b.a[5]; > pc = &(a = b).a[5]; > > printf("%p %p %p\n", pa, pb, pc); > } [...] I think that code has undefined behavior. (a = b) is an rvalue that refers to an object of type struct S with temporary lifetime. pc holds the address of a subobject of that temporary object. The object reaches the end of its lifetime at the end of the evaluation of the full expression. You then print its value. And more obviously, "%p" requires an argument of type void*, not int*. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */