Tag: arm代码源

GCC C ++(ARM)和const指向struct字段的指针

假设有一个简单的测试代码 typedef struct { int first; int second; int third; } type_t; #define ADDRESS 0x12345678 #define REGISTER ((type_t*)ADDRESS) const int data = (int)(&REGISTER->second)*2; int main(void) { volatile int data_copy; data_copy = data; while(1) {}; } 这是用于裸机ARM的CodeSourcery G ++(gcc 4.3.2)编译的。 它还有一个非常标准的链接描述文件。 当用C编译(作为main.c)时,对象“data”进入Flash,如预期的那样。 当用C ++编译时(作为main.cpp),这个对象进入RAM,并添加了额外的代码,只是将值从Flash复制到RAM(该值已经计算,只需复制!)。 所以编译器可以计算地址,但不知何故不想“只使用它”。 问题的根源是地址的乘法 – 没有“* 2”乘法,两个版本都按预期工作 – “数据”放在Flash中。 另外 – 当“数据”被声明为: const int […]