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: Thu, 29 May 2025 13:56:38 -0700 Organization: None to speak of Lines: 54 Message-ID: <87wm9zdtkp.fsf@nosuchdomain.example.com> References: <86plgo7ahu.fsf@linuxsc.com> <20250505111213.00004b55@yahoo.com> <20250505120145.000014f8@yahoo.com> <87jz6uhkgo.fsf@nosuchdomain.example.com> <1019j3e$3rqk1$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Thu, 29 May 2025 22:56:39 +0200 (CEST) Injection-Info: dont-email.me; posting-host="35ee183a1de7bb444a1794cff417189d"; logging-data="64426"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Y1SMZlsfL0PNtbnrcHU1S" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:2r0e5V3FV22NuIb/aJfebxwdC78= sha1:i6sp8RlNWHpMbAvW4xH+/nptPUo= Andrey Tarasevich writes: > On Mon 5/5/2025 1:27 PM, Keith Thompson wrote: >> 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", (void *) pa, (void *) pb, (void *) pc); >>> } >>> >>> This version has no UB. >> I believe it does. pc points to an element of an object with >> temporary lifetime. The value of pc is then used after the object >> it points to has reached the end of its lifetime. At that point, >> pc has an indeterminate value. > > Nope. Nowhere in this code the value of `pc` is used beyond the > lifetime of the object with temporary lifetime. > > Pay attention to the fact that the last 4 lines in above code is a > single expression joined by a comma operator, which is the whole point > of the corrections that differentiate it from the original version. Yes, yes, the fact that the code uses comma operators rather than semicolons was pointed out and discussed several weeks ago. I initially missed that change, it was pointed out, I acknowledged it, and we moved on. If you're going to reply to an old article, please read the thread before posting. In response to something else you recently wrote in this thread, the change from semicolons to commas was not at all obvious. The code is formatted in a way that strongly suggests statements with ending semicolons. Several of us missed the commas on first reading, having seen nearly identical code earlier in the thread with no acknowledgement that the code had been modified. I simply assumed that it was the same code, and didn't bother to re-read it character by character. [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */