Array access via pointer

Pelle pelle.mansson at gmail.com
Sun May 30 13:16:55 PDT 2010


On 05/30/2010 09:43 PM, Robert wrote:
> Hi, I hope some of you D gurus can help me getting my mind setup correct
> when using D arrays.
>
> I have an array: data[1 .. 2048] of type ubyte
>
> I'm interested in getting the addresse of the array and its data
> members. So I used:
>
> writefln("adress data[%d] = %d", 0, &data);
> writefln("adress data[%d] = %d", 2047, &data[2047]);
>
>
> And got:
>
> address data[0] = 18FE50
> address data[2047] = 2607FF
>
> Which is:
>
>> 0x2607ff - 0x18fe50
> ans = 0x000D09AF
> ans = 854447
>
> Shouldn't these addresses have a difference of 2047 bytes? Why do I get
> those strange addresses back?
>

&data[0] and &data are very different things, if you have a dynamic array.


More information about the Digitalmars-d mailing list