Compiling to 68K processor (Maybe GDC?)
Johan Engelen
j at j.nl
Mon Jan 21 17:08:23 UTC 2019
On Saturday, 19 January 2019 at 17:45:41 UTC, Patrick Schluter
wrote:
> Afaict NULL pointer derefernecing must fault for D to be
> "usable". At least all code is written with that assumption.
Dereferencing `null` in D is implementation defined
(https://dlang.org/spec/arrays.html#pointers).
For LDC, dereferencing `null` invokes Undefined Behavior [1].
However, the compiler does try to be a little friendly towards
the programmer. UB includes just ignoring the dereference, but if
you are blatantly dereferencing `null` with optimization enabled,
the compiler generates a `ud2` instruction for you:
https://d.godbolt.org/z/5VLjFt
-Johan
[1] Now I am not quite sure yet whether Undefined Behavior is
part of the set of behaviors allowed to choose from for
Implementation Defined behavior. ;-)
More information about the Digitalmars-d-learn
mailing list