最近在使用lib在alloc内存时,会需要检查当初alloc时的位址的alignment
如下面
#define alignof __alignof
#define ISALIGNED_N(ptr, n) (((uintptr_t)(ptr) & ((n) - 1)) == 0)
if (!ISALIGNED_N(mem, alignof(unsigned long long)))
printf(“check align fail!\n”);
else
printf(“check align ok!\n”);
很好奇为什么下面位址都是check align ok
alignof(unsigned long long)不是代表位址可以被8整除吗?
0x7f4a5c0191cc
0x7f4a5c0391e4
0x7f4a5c0591fc
0x7f4a5c079214
0x7f4a5c09922c
0x7f4a5c0b9244
0x7f4a5c0d925c
谢谢