Walter Bright:

struct VolatilePointerToUint {
  private:
    size_t ptr;
  public:
    this(size_t ptr) { this.ptr = ptr; }
    uint read() { return peek(cast(uint*)ptr); }
    void write(uint value) { poke(cast(uint*)ptr, value); }
}

You'd probably wish to flesh this out a bit more, but it's the general idea.

To be added to Phobos?


It's a zero cost abstraction. D has very capable abilities to create types that are restricted versions of other types - this should be explored and exhausted before considering language extensions.

See also the @fantom suggested by Kagamin.

Bye,
bearophile

Reply via email to