2013/4/2 <[email protected]>"@puremagic.com <"\"Luís".Marques">
> On Tuesday, 2 April 2013 at 02:52:48 UTC, Steven Schveighoffer wrote:
>
>> You see, indexing does NOT dereference the pointer, it's an index for
>> that pointer. c[0] means *(c + 0). A pointer is essentially an unchecked
>> slice, with undefined length. This is how it works in C also.
>>
>> c[1] is the same as *(c + 1), completely consistent (and also sets b to
>> 42, 42)
>>
>
> OK, I think I see where I went astray. I was a case of bad induction from
> a few tests :-)
> So, I guess what is happening is the following, right?
>
> int[2] a;
>
> int[2] *c;
> c = &a;
>
> c[0] = 7; // same thing as below
> a = 7; // same thing above
>
These are doing that element-wise assignment.
c[0][] = 7; // same as c[0][0] = c[0][1] = 7;
a[] = 7; // same as a[0] = a[1] = 7;
As a side note:
>From 2.063, lack of [] for array operation would be warned with -w switch.
So, there is no "implicit dereferencing".
Kenji Hara