小编Man*_*ada的帖子

编译时进行C数组对齐检查

我试图在编译时检查8的数组对齐.这是代码:

// File scope
uint32_t pool[1024];
bool aligned = (((uintptr_t) pool) % 8) == 0;
Run Code Online (Sandbox Code Playgroud)

我收到此错误:初始化元素在加载时不可计算.但是,当我检查4的数组对齐时,我没有得到错误.代码如下:

// File scope
uint32_t pool[1024];
bool aligned = (((uintptr_t) pool) % 4) == 0;
Run Code Online (Sandbox Code Playgroud)

语言:C

工具链:arm-none-eabi-gcc

编译器选项:-mcpu = cortex-m3 -mthumb

为什么会这样?

c embedded gcc arm

5
推荐指数
2
解决办法
642
查看次数

标签 统计

arm ×1

c ×1

embedded ×1

gcc ×1