Implicit dereferencing
kenji hara
k.hara.pg at gmail.com
Mon Apr 1 21:50:17 PDT 2013
2013/4/2 <luismarques at gmail.com>"@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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130402/20150d7d/attachment-0001.html>
More information about the Digitalmars-d
mailing list