Casting Pointers?
Rene Zwanenburg via Digitalmars-d
digitalmars-d at puremagic.com
Thu May 12 02:32:17 PDT 2016
On Thursday, 12 May 2016 at 08:41:25 UTC, John Burton wrote:
> Is this legal / valid in D and if not what is the appropriate
> way to efficiently access data like this?
Phobos / druntime use casts like this as well, but there has been
some discussion as to whether it should be guaranteed to be
correct. There are good reasons the C folks disallow it (well,
performance of course, what else? ^^), and the reasoning applies
to D as well.
In this case, you can use a union:
union DL
{
double d;
long l;
}
auto dl = DL(1.0);
writeln(dl.l);
More information about the Digitalmars-d
mailing list