我的嵌入式系统有两个内存区域。我创建了在这些区域之间切换的宏。我希望能够在编译时执行这些宏,但我为某些操作获取了error: initializer element is not constant
,而不是其他操作。我已经把这个例子总结成这样。以下是全局变量:
__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
看起来我不能做除法或移位,但是加法或减法都可以。
我最初在尝试减去一个固定的偏移量,然后除以4的时候遇到了这个问题,也许有一种更简单的方法可以做到这一点?我正在使用(GCC) 7.2.0
https://stackoverflow.com/questions/50770414
复制相似问题