Pointer, if pointed type is unknown?

Daniel Gibson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 2 15:55:18 PDT 2014


Am 02.08.2014 22:21, schrieb seany:
> In my previous post
> (http://forum.dlang.org/thread/jcaomfduqeofobculgli@forum.dlang.org) I
> asked for an array of pointers to different types, as a stack for my
> own, where I can generate and insert runtime variables.
>
> However, seems like I need to know the type of variable the pointer is
> pointing to. That is,
>
> double pi = 3.14159;
> size_t ptr = cast(ulong)π // so far oky
>
> double pi_2 = *ptr; // this is where things break down
>
> won't work.
>
> What can I do if the type of the variable is not known?
>

if you really think you have to do this (and not use variants or 
something): use an appropriate cast,
i.e. double pi_2 = *(cast(double*)ptr);
furthermore: why not use void* instead of size_t?

Cheers,
Daniel


More information about the Digitalmars-d-learn mailing list