Выравнивание объектов в памяти в соответствии с ISO/IEC 9899:2024
Поясните, пожалуйста, правильно ли я понимаю это понятие.
Выдержка из стандарта про термин alignment:
Requirement that objects of a particular type be located on storage boundaries with addresses that are particular multiples of a byte address.
Перевод:
Требование, чтобы объекты определенного типа располагались на границах хранилища с адресами, которые являются конкретными кратными байтового адреса.
Я понимаю это так, что значение любой переменной в памяти реализация должна распределить на целое число байт, то есть структура с битовым полем, меньшим байта, будет занимать один или более байтов, правильно?
Ответы (1 шт):
О том, как значения хранятся в памяти, говорится в разделе
6.2.6 Representations of types
4 Values stored in non-bit-field objects of any other object type are represented using n×CHAR_BIT bits, where n is the size of an object of that type, in bytes. An object that has the value may be copied into an object of type unsigned char [n] (e.g. by memcpy); the resulting set of bytes is called the object representation of the value. Values stored in bit-fields consist of m bits, where m is the size specified for the bit-field. The object representation is the set of m bits the bit-field comprises in the addressable storage unit holding it.