On 04/01/2013 05:07 PM, "Luís Marques" <[email protected]>" wrote:> Consider this (non-portable) code:

Perhaps it is obvious to everyone but allow me still: It is not non-portable code, but its behavior is undefined.

> {
>      int[2] a;
>      int[2] b;
>      int[2] *c;

c is a pointer to a single int[2].

>      c = &a;
>
>      c[0] = 7;
>      assert(a[0] == 7); // OK, as expected
>
>      c[1] = 42;
>      assert(b[0] == 42); // do we really want this semantics?

A manifestation of undefined behavior.

> But "c[1] = 42" is equivalent to "(*(c+1)) = 42", which might not be
> obvious. In this case it ends writing to b[0].

It seems to be so but it is not defined to work that way.

Ali

Reply via email to