How does D improve design practices over C++?

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Oct 29 20:11:59 PDT 2008


On Wed, Oct 29, 2008 at 7:15 PM, Frits van Bommel
<fvbommel at remwovexcapss.nl> wrote:
> 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)

I kind of imagined it would.  I thought the entire point of SafeD
would be that the language would completely disallow you from touching
memory that you don't own.  Which would include Java-like null
reference checks.



More information about the Digitalmars-d mailing list