| Deutsch English Français Italiano |
|
<vvdhb2$3m8gn$1@paganini.bofh.team> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: comp.lang.c
Subject: Re: Regarding assignment to struct
Date: Tue, 6 May 2025 17:36:36 -0000 (UTC)
Organization: To protect and to server
Message-ID: <vvdhb2$3m8gn$1@paganini.bofh.team>
References: <vv338b$16oam$1@dont-email.me> <vv4j9p$33vhj$1@dont-email.me> <86plgo7ahu.fsf@linuxsc.com> <vv9hu7$3nomg$1@dont-email.me> <20250505111213.00004b55@yahoo.com> <vv9stv$2i8j$1@dont-email.me> <20250505120145.000014f8@yahoo.com> <vvame5$ppqp$1@dont-email.me> <87jz6uhkgo.fsf@nosuchdomain.example.com>
Injection-Date: Tue, 6 May 2025 17:36:36 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="3875351"; posting-host="WwiNTD3IIceGeoS5hCc4+A.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Notice: Filtered by postfilter v. 0.9.3
Bytes: 2310
Lines: 36
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Andrey Tarasevich <noone@noone.net> writes:
> [...]
>> #include <stdio.h>
>>
>> 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.
>
> N3096 6.2.4p2: "If a pointer value is used in an evaluation after
> the object the pointer points to (or just past) reaches the end of
> its lifetime, the behavior is undefined. The representation of a
> pointer object becomes indeterminate when the object the pointer
> points to (or just past) reaches the end of its lifetime."
Note commas above. Assignment to pc and call to printf are parts
of a single expression, so use of pc is within lifetime of the
temporary object.
--
Waldek Hebisch