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
(cast(int*) c)[0] = 7; // but different from this
I verified that c is a pointer to a.ptr, I guess what I didn't
consider is that because c points to int[2], the assignment
becomes the same as a = 7, and not a[0] = 7.
Still, what do you think of the struct vs AA automatic pointer
dereferencing?