错误说明
错误含义:将4byte写入大小为1byte的区域;
自己检查多次之后,发现代码写法并没有问题,那么就很有可能是 结构体对齐 的问题,导致实际使用内存区域和结构体命名内存区域不一致;
解决方法
1:去掉 makefile 里面的编译选项 “-Werror -Wall”,这样会忽略该警告;
2:修改结构体对齐顺序
// 结构体没有4BYTE对齐
typedef struct TestStructName
{
UInt8 test1;
UInt16 test2;
UInt8 test3;
UInt32 test4;
UInt8 test5;
UInt16 test21;
UInt32 test22;
};
// 将结构体修改为4BYTE对齐
typedef struct TestStructName
{
UInt8 test1;
UInt8 test3;
UInt8 test5;
UInt8 test_add;
UInt16 test2;
UInt16 test21;
UInt32 test4;
UInt32 test22;
};