Undo struct slicing by type-punning

ponce via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 14 14:35:34 PDT 2014


On Monday, 14 July 2014 at 18:43:36 UTC, Ali Çehreli wrote:
> It is guaranteed by the language spec that yes, myFunction() 
> takes an A by reference. However, you can't know where that A 
> is coming from; so, the safety of that cast is up to you. 
> Consider:
>
> void foo(A a)         // <-- Already sliced
> {
>     myFunction(a);    // <-- Will perform invalid cast
> }
>

Indeed, the code I port do that because struct have a type-tag.



More information about the Digitalmars-d-learn mailing list