C `restrict` keyword in D

Johan Engelen via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 6 12:40:16 PDT 2017

On Tuesday, 5 September 2017 at 22:59:12 UTC, Jonathan M Davis 
> dmd and the spec were written with the assumption that the CPU 
> is going to segfault your program when you dereference a null 
> pointer. In the vast majority of cases, that assumption holds.

In my terminology, "dereference" is a language spec term. It is 
not directly related to what the CPU is doing.
struct S {
   void nothing() {}

void foo (S* s) {
   (*s).nothing(); //dereference must crash on null?
If you call the `(*s)` a dereference, then you are agreeing with 
"my" dereference terminology. ( used the * for extra clarity; 
"s.nothing()" is the same.)

In LDC, dereferencing a null ptr is UB.
DMD is assuming the same, or something similar. Otherwise DMD 
wouldn't be able to optimize foo in this example to an empty body 
as it does currently.
(go go null-checks everywhere)


More information about the Digitalmars-d mailing list