I'm working with an API that gives me a pointer for memory-mapped I/O. It does this by filling in a pointer-to-pointer argument:
int map(void** p);
Because this is memory mapped I/O, I'm pretty sure I should be using volatile
here. (I don't know why they didn't make the parameter a volatile void**
.)
But, my volatile void**
isn't implicitly convertible to the function's void**
, so I can't just pass it in directly:
volatile void* p;
map(&p); // Error: no known conversion from 'volatile void **' to 'void **'.
I'm currently working around this with an extra variable and a separate assignment step:
volatile void* p;
void* pNonVolatile;
map(&pNonVolatile);
p = pNonVolatile;
This seems verbose. Is it safe in this case to instead cast the volatile
away when passing the pointer in? i.e.
volatile void* p;
map(const_cast<void**>(&p));