Liste des Groupes | Revenir à cl c |
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: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", pa, pb, pc);
}
[...]
>
I think that code has undefined behavior.
Right. [*]
>(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.
Even if the printf() statement were replaced by
>
(void)pc;
>
the behavior would be undefined, because the pointer held in pc
becomes indeterminate as soon as the statement containing the
assignment to pc completes.
[*] Assuming C11 semantics. At best inadvisable under C99
semantics, and a constraint violation under C90 semantics.
Les messages affichés proviennent d'usenet.