www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - safe fun alayws call system function?

reply Dsby <dushibaiyu yahoo.com> writes:
How can i call  system function in a  safe function?
Jul 12 2016
parent reply ag0aep6g <anonymous example.com> writes:
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
Jul 12 2016
parent Dsby <dushibaiyu yahoo.com> writes:
On Tuesday, 12 July 2016 at 09:17:37 UTC, ag0aep6g wrote:
 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
Thanks!
Jul 12 2016