Shouldn't casting an object to void* be considered @safe?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Sun Dec 15 11:15:22 UTC 2019


On Sunday, 15 December 2019 at 09:32:12 UTC, Joseph Rushton 
Wakeling wrote:
> BTW, note that the spec defines a @safe function as one that 
> has been statically checked to exhibit no undefined behaviour.
>
> Casting from an non-pointer type to a pointer seems a pretty 
> good example of something that makes it impossible to 
> statically confirm that no undefined behaviour is taking place.

Not impossible?

It only becomes a problem if @trusted code do unsafe things, like 
taking *void pointers that it intends to dereference.

You just need to show that *void pointers that @safe code can 
write to are not dereferenced.



More information about the Digitalmars-d mailing list