Compiling to 68K processor (Maybe GDC?)

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Jan 22 02:29:45 UTC 2019


On Monday, January 21, 2019 10:08:23 AM MST Johan Engelen via Digitalmars-d-
learn wrote:
> 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. ;-)

It is my understanding that Walter specifically chose the term
"implementation defined" rather than "undefined," because undefined behior
is not allowed, and that page you linked to supports that in that it lists
"implementation defined" and "undefined" separately when talking about the
behavior of dereferencing pointers. But you would have to discuss it with
Walter to know exactly what he meant. The spec really should define those
terms somewhere, but I doubt that it does. I haven't read through the spec
in much detail recently though, so maybe it's in there somewhere.

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list