Liste des Groupes | Revenir à l c |
Andrey Tarasevich <noone@noone.net> writes:Nope. Nowhere in this code the value of `pc` is used beyond the lifetime of the object with temporary lifetime.
[...]#include <stdio.h>I believe it does. pc points to an element of an object with
>
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.
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 afterNot applicable in this case.
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."
Les messages affichés proviennent d'usenet.