volatile variables in D....

Rory McGuire rjmcguire at gmail.com
Wed Mar 19 02:51:50 PDT 2008


Wouldn't it be better to have an object which represents the actual device/port
that you are reading/writing?
This would also make the code's actions more obvious.

class Port { // (Could also be a struct)
    size_t port; // this is a pointer to the memory mapped io port

    this(size_t port) {
        this.port = port;
    }
    byte read() {
        volatile return *port;
    }
    void write(byte value) {
        volatile *port = value;
    }
}

Anyone still reading this thread?



More information about the Digitalmars-d mailing list