D equivalent of C++ reinterpret cast?

Jonathan M Davis jmdavisProg at gmx.com
Sun Sep 19 19:21:18 PDT 2010


On Sunday 19 September 2010 17:07:38 bearophile wrote:
> orgoton baberek:
> > Use a union, which is the correct and safe way.
> 
> C standard say that's not safe. You can force that to be safe in C-GCC if
> you explicitly disable a compiler optimization. I think D docs don't say
> anything about this. And Walter has said that regarding such things D acts
> as C. So I am not sure that will be safe in future D.
> 
> Bye,
> bearophile

I'd have to go digging in old posts, but I'm pretty sure that that's essentially 
how you're supposed to do it in D. I haven't ever done it because I think that 
that sort of casting is pretty evil and only should be used as a last resort, 
but I believe that unions are the correct way to handle it in D. It's been 
discussed before, I'm fairly certain, though I think that the last place that I 
saw it was buried in a topic on a specific problem rather than anything 
necessarily particularly searchable in the archives.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list