@safe fun alayws call @system function?

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 12 02:17:37 PDT 2016


On 07/12/2016 11:09 AM, Dsby wrote:
> How can i call @system function in a @safe function?

You can't. You can mark the @safe function @trusted [1] instead. 
@trusted functions are considered memory-safe by the compiler and can be 
called from @safe code, but they can use @system features and call 
@system functions.

A @trusted function must still be memory-safe, and the compiler cannot 
check that it is, so you as the programmer take on the responsibility to 
ensure that the function is in fact memory-safe.

Be very careful with @trusted and make sure you know exactly what you're 
doing. A bad @trusted function compromises the whole call chain.


[1] https://dlang.org/spec/function.html#trusted-functions


More information about the Digitalmars-d-learn mailing list