I am working on a built-in target and want to define memory pools.
Memory addresses are represented as void*. However, in the specific case, these addresses are cached, and I want to be able to link them to directly get the "real" hardware address.
I want to determine the start address memory_area(which is just a marker):
#define UNCACHE_MASK 0xABCDEF12UL
extern uint32_t memory_area;
const void * virtual_address = &memory_area;
const void * real_address =
(void*)(virtual_address | UNCACHE_MASK);
Unfortunately, GCCwon't let me do this:
error: invalid operands to binary | (have 'const void *' and 'long unsigned int')
In desperation, I tried:
const void * real_address =
(void*)(((uint32_t)virtual_address) | UNCACHE_MASK);
In vain:
error: initializer element is not constant
I really want to keep constit safe: is this achievable?
[EDIT]
- I am using
GCCv4.9 (with -std=gnu99and many flags -Wxxx) on Linux. - Excerpt from the file
.h, the variables are "global."