Global const variables
Solomon E via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 21 09:47:04 PDT 2014
On Tuesday, 21 October 2014 at 14:25:20 UTC, ketmar via
Digitalmars-d-learn wrote:
> On Tue, 21 Oct 2014 13:43:29 +0000
> Solomon E via Digitalmars-d-learn
> <digitalmars-d-learn at puremagic.com>
> wrote:
>
>> `b[0] = 8;` or `b[] = 8;` changes a. Printing the values for
>> &a and &b shows they're different pointers, but (a is b)
>> returns true. So I still have more to learn about how it does
>> that.
> that's 'cause '&b' taking address of hidden "array structure",
> not
> the first array element, as in C. try 'a.ptr' and 'b.ptr' to get
> addresses of array elements.
Thanks, that's what I was looking for, in order to understand
what's going on. I Googled for it on this site, but without
remembering the keyword ptr, I didn't find anything relevant.
After I put printouts of .ptr in my test program, I figured out
how to get the same result by unsafe pointer arithmetic.
Apparently, for an array a, a.ptr == *(cast(ulong*) &a + 1).
That's unsafe because the implementation might change, and
pointer arithmetic is unsafe in general.
More information about the Digitalmars-d-learn
mailing list