On Thursday, 17 October 2013 at 23:08:13 UTC, Ali Çehreli wrote:
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. ;)


I tried this code and the compiler allowed it (runtime I get object.Error: Access Violation). What am I doing wrong?

Thanks I didn't notice

@safe
import std.stdio;
class A {
        int x  = 1;
}
@safe void main() {
        A a;
        a.x=9;
}

Reply via email to