How does D improve design practices over C++?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Wed Oct 29 16:15:01 PDT 2008


Jarrett Billingsley wrote:
> Interestingly, although null dereferences are unsafe, in a safe
> language like SafeD it's not actually possible to do so.  There are no
> pointers and arrays are bounds-checked.  So with the combination of
> the typing system and the runtime checks, null can never actually be
> dereferenced, so no special consideration has to be given to it.

Assuming it still allows heap-allocated objects, something like this 
will still work:
----
class C {
     ubyte[16 * 1024 * 1024 - 1] memory;
}

void poke(size_t intptr, ubyte b) {
     C c; // kept at null deliberately
     c.memory[intptr - c.memory.offsetof] = b;
}

ubyte peek(size_t intptr) {
     C c; // kept at null deliberately
     return c.memory[intptr - c.memory.offsetof];
}
-----

(That is, unless it emits 'this' null-checks for object field accesses 
as well)



More information about the Digitalmars-d mailing list