On 7/15/2014 4:52 PM, Steve Sobel wrote:
So in my opinion, and without prescribing the exact solution,
volatility is an important enough concept in embedded to merit a
standard solution that can be mechanically verified.

There is another way. The peek() and poke() functions are primitive. You can wrap a "pointer to volatile" in its own type, and in that type, control access to the pointer so it cannot be used outside of peek/poke.

For example, off the top of my head:

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. 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.

Reply via email to