@safe by default

Mike Franklin slavo5150 at yahoo.com
Sun Jun 17 12:07:14 UTC 2018


On Saturday, 16 June 2018 at 13:52:37 UTC, Jacob Shtokolov wrote:

> Is it possible to introduce a new parameter/flag to the 
> compiler, to force all functions be @safe by default on a 
> per-module basis?

Forgive me if you're already aware of this, but to ensure your 
entire program is `@safe` (assuming it's single threaded) you 
only need to attribute `main` with `@safe`.  This is because 
`@safe` functions cannot call unsafe functions and will emit a 
compiler error if attempting to do so.

You still may need to attribute called functions with `@safe` or 
`@trusted` as necessary, and as others have already explained, 
but your program will enforce `@safe`ty simply by attributing 
`main`.

Mike




More information about the Digitalmars-d mailing list