what exactly does cast(shared) and cast away shared do?
Petar
Petar
Tue Jun 16 07:35:08 UTC 2020
On Tuesday, 16 June 2020 at 07:22:59 UTC, mw wrote:
>
> Thanks for the explanation. I've thought &foo will return the
> address of that actual object, just as &(foo.attr) does for
> .attr.
To get the actual address, you need to cast the class reference
to a pointer:
https://run.dlang.io/gist/run-dlang/ea2b163f0fd90e16adc72ab78ed48553?compiler=dmd
> So cast(shared) and cast away shared only affect the type
> system, the actual object will always stay the same, and there
> is not any magic operation or wrapper behind the scene.
>
> `shared` or not is purely a compile-time attribute, not some
> runtime dynamic attribute on the object, i.e. at runtime when
> you get hold of an object on the heap, there's no way you can
> tell from the object itself whether it's shared or not.
Yes, exactly.
More information about the Digitalmars-d
mailing list