Shouldn't casting an object to void* be considered @safe?
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Sat Dec 14 18:21:06 UTC 2019
On Saturday, 14 December 2019 at 18:10:20 UTC, Ola Fosheim
Grøstad wrote:
> Sometimes you just want a set of all object identities with a
> specific property so that you can query for that property.
>
> It is the same a the "tag" reference type in Pony lang. It is
> safe for multi-threading too.
>
> Say, if a thread is waiting for a set of futures to complete
> then it can remove object identities from the set based on
> events.
Fair enough, but note that the safety of the `void*` in those
use-cases is still down to the specifics of how they are used.
The obligation to put a `@trusted` on the cast to `void*` for
use-cases like this seems minor compared to the value of
explicitly nudging the developer to verify that the use-case is
safe.
IOW, having casts to `void*` be unsafe seems a tactic, rather
than a principle.
More information about the Digitalmars-d
mailing list