Cast a struct to void*
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 9 10:35:55 PST 2015
On Friday, 9 January 2015 at 18:25:42 UTC, John Colvin wrote:
> struct S
> {
> void* p;
> }
>
> void main()
> {
> S s;
> auto a = cast(void*)s; //Error: e2ir: cannot cast s of type
> S to type void*
> }
>
> Is there are a good reason for this being disallowed?
You'd expect `cast(void*)s == s.p`? That doesn't work for any
type of p. You can do it with a slightly fancier (and more
dangerous) cast: `*cast(void**)&s`.
More information about the Digitalmars-d-learn
mailing list