On Saturday, 16 August 2025 at 15:14:21 UTC, H. S. Teoh wrote:
On Sat, Aug 16, 2025 at 03:03:21PM +0000, Brother Bill via Digitalmars-d-learn wrote: [...]
I'm not sure we are on the same page.
My question is whether having a pointer to invalid memory causes problems. I am fully aware that reading or writing to an invalid
memory address causes problems.

I am grasping that even having a pointer pointing to an invalid memory address is a huge code smell. But will it cause any undefined behavior merely having a pointer with an invalid memory address.

What do you mean by "cause any undefined behaviour"? UB is defined by the language spec, which states that assigning a non-pointer value (or a random garbage value) to a pointer is UB. What it actually does at runtime is orthogonal to this. At the machine level, there is no UB, it's simply following the instructions you gave it literally. That the results may not be what you expect is a problem at a higher level of abstraction.




So a good D developer should not store an invalid pointer address into a pointer, with the single exception of storing a pointer address just past a slice or array.

  • Pointers - Is it... Brother Bill via Digitalmars-d-learn
    • Re: Pointer... H. S. Teoh via Digitalmars-d-learn
    • Re: Pointer... Brother Bill via Digitalmars-d-learn
      • Re: Poi... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • 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
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... monkyyy via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... monkyyy via Digitalmars-d-learn

Reply via email to