Har*_*nry 4 c gcc arm alignment
我有一些类似于以下内容的代码:
void somefunc(uint64_t val) {
uint8_t *p;
uint8_t *s;
s = calloc( (max_sa_len + sizeof(uint64_t) - 1) / sizeof(uint64_t), sizeof(uint64_t));
// s must be 8 byte aligned here
p = (s + sizeof(uint64_t));
// p must be 8 byte aligned here
*(uint64_t)*p = hton64(val & 0xffff);
...
}
Run Code Online (Sandbox Code Playgroud)
当我编译时,我得到:
file.c:400:10: error: cast increases required alignment of target type [-Werror=cast-align]
Run Code Online (Sandbox Code Playgroud)
有没有一种干净的方法来解决这个警告? s,因此p 必须与 64 位地址对齐,这不是真正的错误。我尝试p=__builtin_assume_alinged(p,8);在代码中添加一个,但它没有修复错误。我在使用 arm32 (v7) gcc 交叉编译器 v 4.7.0 时遇到此错误
uint64_t *s_u64 = calloc( (max_sa_len + sizeof(uint64_t) - 1) / sizeof(uint64_t),
sizeof(uint64_t));
s = s_u64; // if you need to address by byte as well
...
s_u64[1] = hton64(val & 0xffff);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1042 次 |
| 最近记录: |