My embedded system has two regions of memory. I created macros to switch between these regions. I would like to be able to execute these macros at compile time but I'm getting error: initializer element is not constant
for certain operations and not others. I've boiled down the example to this. These are global variables:
__attribute__((section(".vmem_constant.data"))) unsigned int buf0[1024];
unsigned int buf_word_ptr = ((unsigned int)buf0)>>2; // doesn't work
unsigned int buf_word_ptr2 = ((unsigned int)buf0)/4; // doesn't work
unsigned int buf_word_ptr3 = ((((unsigned int)x)-0x40000)>>2); // original problem doesn't work
unsigned int works_1 = ((unsigned int)buf0) + 2; // works
unsigned int works_2 = buf0 + 16; // works
It seems like I can't do a divide or bitshift, however add or subtract is ok.
I originally ran into this when I was trying to subtract a fixed offset, and then divide by 4. Maybe there is an easier way to do this? I'm using (GCC) 7.2.0