The so called placement new does this :
Code:
volatile int32_t* myVar = new((void*)0x12345678) int32_t;
If you don't want to bother dereferencing the pointer everytime you use it, you can do something like :
Code:
volatile int32_t* myVarPtr = new((void*)0x12345678) int32_t;
volatile int32_t& myVar = *myVarPtr;
However, every access to the variable involves one indirection more than your first proposition (the #define).
The question being : does your solution provide a significant performance enhancement? OTOH it obviously makes it harder to maintain the program.
As far as I'm concerned, I'd go with the placement new option., as it is way cleaner.
Remember: premature optimization is the root of all evil
Bookmarks