pointer array?

FreeSlave via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 31 03:51:02 PDT 2014


On Wednesday, 30 July 2014 at 20:51:25 UTC, Daniel Kozak via 
Digitalmars-d-learn wrote:
> V Wed, 30 Jul 2014 14:33:51 +0000
> seany via Digitalmars-d-learn 
> <digitalmars-d-learn at puremagic.com>
> napsáno:
>
>> In Ali's excllent book, somehow one thing has escaped my 
>> attention, and that it the mentioning of pointer arrays.
>> 
>> Can pointers of any type of pointed variable be inserted in an 
>> int array? Using to!(int) perhaps? If not directly, then what 
>> else would achieve the same effect?
>
> It depends on pointer size, for eg, on 64bit system with 64bit 
> pointers
> something like this should works:
> long[] arr = (cast(long*)pointersArray.ptr)[0 .. 
> pointersArray.length];
> or
> long[] arr = cast(long[])pointersArray; // but I am not sure if 
> this is
> OK

Don't use long in this case, use size_t and ptrdiff_t. They are 
required to be integer types with size of pointer (size_t is 
unsigned, ptrdiff_t is signed)


More information about the Digitalmars-d-learn mailing list