Safe mode in D?
Ali Çehreli
acehreli at yahoo.com
Thu Oct 17 16:08:13 PDT 2013
On 10/17/2013 03:56 PM, DDD wrote:
> Hi I heard that you can pass a command line argument to make D safe.
> Like 0 chance of memory corruption and such. I tried looking here
> http://dlang.org/dmd-linux.html but I couldn't figure it out. If it
> matters I'm on windows using the latest until a new version came out
> ~3weeks ago
An example to complement Adam D. Ruppe's answer:
/* @system is the default */
@system void can_do_anything()
{
int a;
int * p = &a;
}
/* Must be @trusted to be able to call function that are safe but not marked
* as such. */
@trusted void bridge_between_safe_and_actually_safe()
{
safe_but_not_marked_as_such();
}
@safe void safeD_function()
{
int a;
// CANNOT BE COMPILED:
// int * p = &a;
// Can call @trusted from @safe
bridge_between_safe_and_actually_safe();
}
void safe_but_not_marked_as_such()
{}
void main()
{
can_do_anything();
bridge_between_safe_and_actually_safe();
safeD_function();
}
Ali
P.S. There is also the D.learn newsgroup. ;)
More information about the Digitalmars-d
mailing list