If optimization level is >= 2 in gcc-4.1, strict-aliasing is used, and this could cause probelms when a pointer is referencing to a different type of object and the object is refered thereafter by using this pointer. That is the case in this example. So you should force the compiler to not use strict-aliasing by a argument "-fno-strict-aliasing" if you want to use "-O2" or "-O3".
就是说 optimization level>=2 默认使用 strict-aliasing, -O0和-O1就没有默认使用 -fstrict-aliasing,导致不同类型的指针指向同一内存就会提示错误。比如:
int i=1;
unsigned int * p=(unsigned int *)(&i);这样是不符合 aliasing规则的。如果使用 -O2 或 -O3 可以使用参数 -fno-strict-aliasing来避免aliasing规则。上面的代码就可以通过编译了。
使用EmBitz 编译mbed提示
.\W5500Interface\WIZnet\W5500.h|321| required from 'void WIZnet_Chip::reg_wr(uint16_t, T) [with T = short unsigne
解决EmBitz编译mbed时的strict-aliasing问题

当使用EmBitz编译mbed项目且优化级别大于等于2时,会遇到strict-aliasing问题导致编译错误。通过添加编译标志'-fno-strict-aliasing'可以禁止strict-aliasing,从而解决这个问题。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



