pointers, assignments, Garbage Collection Oh My?

Ali Çehreli acehreli at yahoo.com
Thu Jul 11 10:07:17 PDT 2013


On 07/11/2013 12:23 AM, Jacob Carlborg wrote:

 > On 2013-07-10 20:22, Ali Çehreli wrote:
 >
 >> And to be pedantic, length comes first:
 >>
 >> struct Array (T)
 >> {
 >>      size_t length;
 >>      T* ptr;
 >> }
 >
 > I thought "ptr" came first, that's the reason you could cast to the
 > pointer type. Not that one should do that. Perhaps there's some
 > compiler/runtime magic involved.

There must be little magic and that magic should be the same as getting 
the .ptr property. Otherwise, the "value" of a struct object cannot be 
casted to pointer type:

struct S
{
     int *p;
}

     auto s = S();
     int *p = cast(int*)s;

Error: e2ir: cannot cast s of type S to type int*

Ali



More information about the Digitalmars-d-learn mailing list