J
Johannes Schaub (litb)
How is it possible in C++ to access a specific port address using volatile
semantics? Here is a wrong way:
int volatile &port = *(int volatile*)0x318f;
This doesn't work according to the Standard, because the observable behavior
does only include read and writes to volatile objects. It does not include
access to potentially non-volatile objects through volatile lvalues.
How can this be solved? It seems a bit weird to me that the main purpose of
volatile was to read out mapped device addresses, but that volatile actually
seems to fail to supply that guarantee?
The only way to me seems to be to do this like
extern int volatile port;
And to map that using the linker to a specific address, but this looks to me
like an ugly solution. What if we compute the address at runtime and want to
do volatile accesses to it?
semantics? Here is a wrong way:
int volatile &port = *(int volatile*)0x318f;
This doesn't work according to the Standard, because the observable behavior
does only include read and writes to volatile objects. It does not include
access to potentially non-volatile objects through volatile lvalues.
How can this be solved? It seems a bit weird to me that the main purpose of
volatile was to read out mapped device addresses, but that volatile actually
seems to fail to supply that guarantee?
The only way to me seems to be to do this like
extern int volatile port;
And to map that using the linker to a specific address, but this looks to me
like an ugly solution. What if we compute the address at runtime and want to
do volatile accesses to it?