.ptr and .value

Timoses timosesu at gmail.com
Thu Mar 29 15:42:04 UTC 2018


On Wednesday, 5 May 2010 at 22:42:19 UTC, Robert Clipsham wrote:
> .ptr is only available for arrays. Internally, (dynamic) arrays 
> in D look like this:
> ----
> struct {
>   size_t length;
>   T* ptr;
> }
> ----

Thanks for this!! (I know this topic is old).
But it made me understand why I found that this is working 
correctly:

   class Storage(T)
   {
     T type;

     this(ref ubyte[] stream)
     {
       static if (isArray!T)
         this.type = cast(T*)(&stream);    // because the array 
should actually
                                           // point to an array
       else
         this.type = cast(T*)(stream.ptr); // because the data 
type T
                                           // should point to the 
actual data
     }
   }

I wonder if the difference of '&' and '.ptr' could be worth 
mentioning here
https://dlang.org/spec/arrays.html

...





More information about the Digitalmars-d-learn mailing list