Safe mode in D?

Adam D. Ruppe destructionator at gmail.com
Thu Oct 17 16:03:51 PDT 2013


On Thursday, 17 October 2013 at 22:56:04 UTC, DDD wrote:
> Hi I heard that you can pass a command line argument to make D 
> safe.

I don't think the command line argument is available anymore, 
instead it uses a function level annotation @safe

So, on the function you want, you put it down and then that 
function can only do memory safe operations and only call other 
@safe, or manually verified @trusted functions.

To get it site wide, you can put it on main:

@safe void main() {
  // memory safe function
}


Note that not all standard library functions are properly marked 
@safe, so not all stdlib functions will be available. Notably, 
writeln() in std.stdio is not marked safe... you can work around 
it by making a @trusted writeln as described here

http://stackoverflow.com/questions/19413340/escaping-safety-with-debug-statements


More information about the Digitalmars-d mailing list