Can't cast from void*

Steven Schveighoffer schveiguy at yahoo.com
Mon Feb 5 15:33:02 UTC 2018


On 2/3/18 12:37 PM, Kagamin wrote:
> ---
> interface A{}
> 
> void* a=cast(void*)5;
> A b=cast(A)a; //ok
> A c=cast(A)cast(void*)5; //error
> ---
> Last line gives Error: cannot cast `void*` to `A`. Is it intended?

Superficially, it looks like it should work, given the previous 2 lines.

But I don't know what the compiler does to convince itself your code is 
wrong when you do it all in one expression.

Is there a more pragmatic use case why this should be possible? It would 
help give motivation for fixing the problem. Clearly, `5` isn't going to 
be a valid interface pointer.

-Steve


More information about the Digitalmars-d-learn mailing list