ILD

local or global array variable alignment
作者:HerbertYuan 邮箱:yuanjp89@163.com
发布时间:2017-10-6 站点:Inside Linux Development

我们经常会定义一个char数组作为缓存接收数据,然后将接收的数据转换为某一个结构体。这里通常要求数组按照结构体的要求对齐。那么默认的cha数组是对齐到多少呢?1还是?如果为1的话,意味着我们要显示地给出对齐要求。查到的资料是,局部或全局数组如果大于16个字节会对齐到16字节。

https://stackoverflow.com/questions/22598992/alignment-of-char-array-struct-members-in-c-standard

An array uses the same alignment as its elements, except that a local or global array variable of length at least 16 bytes or a C99 variable-length array variable always has alignment of at least 16 bytes

Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.