This one is going to be short. I have a question regarding manipulations on device registers. As maybe you guys know, device registers addresses are determined by hardware so in order to write code that uses them you have to create variables with these addresses defined, you cannot let the compiler decide on the addresses. This can be done in a few ways, with pointers and references, like this:
using dev_reg = uint32_t volatile;
dev_reg& MYREG = *(reinterpret_cast<dev_reg*>(0x45FF));
So while you can do something like this I am not sure why wouldn't a programming language such as C++ offer some package of features to make life easier for access to such registers, especially as I heard that volatile
is slowly being removed.
Volatility of memory mapped IO is out of question, and one of the very legit and mandatory use cases of keyword
volatile
. The genius design decisions on early days of C++ allow us to use placementnew
to initialize them correctly, and explicit destructor call to finalize them. These objects are also practical examples of unavoidable singleton which is normaly considered anti-pattern elsewhere.Thanks Žarko for his point on singleton.