On Saturday, 16 August 2025 at 23:42:04 UTC, 0xEAB wrote:
On Saturday, 16 August 2025 at 15:44:45 UTC, Richard (Rikki) Andrew Cattermole wrote:
Source: Programming in D book, page 432, chapter 68.8
Quote: It is valid to point at the imaginary element one past the end of an array.

That is not the spec, the book is wrong.

IMHO the book is *not* wrong but rather vague.
What — I think — the book tries to convey is that you can create a zero-length slice outside of the “range” of the original slice.

Separation of concerns:

1. Other than null, is it within spec to have a pointer pointing to invalid memory.
   I believe the answer is yes.
A pointer can point to any random address, even to memory addresses that don't exist. Merely pointing to an invalid address will not produce UB (undefined behavior)
   It would definitely be a "code smell".

2. Is it within spec to dereference a pointer pointing to invalid memory?
   Dereferencing null is not valid.
Dereferencing a pointer pointing to invalid memory in not valid and can result in UB.
      • Re: Poi... H. S. Teoh via Digitalmars-d-learn
      • Re: Poi... Brother Bill via Digitalmars-d-learn
        • Re:... H. S. Teoh via Digitalmars-d-learn
        • Re:... Brother Bill via Digitalmars-d-learn
          • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
            • ... Brother Bill via Digitalmars-d-learn
              • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
              • ... monkyyy via Digitalmars-d-learn
            • ... 0xEAB via Digitalmars-d-learn
              • ... 0xEAB via Digitalmars-d-learn
              • ... Brother Bill via Digitalmars-d-learn
              • ... Monkyyy via Digitalmars-d-learn
              • ... Brother Bill via Digitalmars-d-learn
              • ... Monkyyy via Digitalmars-d-learn
          • ... Monkyyy via Digitalmars-d-learn
          • ... Ali Çehreli via Digitalmars-d-learn
            • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
              • ... Monkyyy via Digitalmars-d-learn
  • Re: Pointers - I... Monkyyy via Digitalmars-d-learn
  • Re: Pointers - I... Paul Backus via Digitalmars-d-learn

Reply via email to