[Issue 24772] Casting class references to void* should be @safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 19 17:08:19 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24772

Tim <tim.dlang at t-online.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tim.dlang at t-online.de

--- Comment #6 from Tim <tim.dlang at t-online.de> ---
(In reply to Richard (Rikki) Andrew Cattermole from comment #1)
> The only thing you can do once you cast it is cause program corruption.
> 
> Is there a benefit to being able to do this in ``@safe`` that I am not aware
> of?

One use case is printing the address of an object:
```
    auto o = new Object();
    writeln(cast(void*) o);
```

Addresses could also be compared for equality or used as keys in associative
arrays.

--


More information about the Digitalmars-d-bugs mailing list