Memory alignment restricts the memory addresses at which an object may begin. An alignment of bytes means that its starting byte address satisfies . For example, address satisfies eight-byte memory alignment, whereas address does not. Alignment is a constraint on location, rather than another name for an object's size.
In the C programming language, object types have alignment requirements;
_Alignof queries a type's requirement and _Alignas can request a supported stronger requirement. The actual values depend on the implementation. The C11 draft distinguishes fundamental from implementation-supported extended alignments and requires valid alignment values to be powers of two.[ref]An application binary interface makes such choices concrete. Under the ordinary AAPCS64 layout, a C structure containing a
char tag followed by a double value has the character at offset , seven unused padding bytes, and the double at offset . Its total size is bytes and its alignment is bytes. The application binary interface aligns an aggregate as strictly as its most strictly aligned member and rounds the aggregate size up to a multiple of that alignment; this also keeps each element properly aligned in an array of these structures.[ref]This example is an explicit platform convention, rather than a universal promise that every C
double needs eight-byte memory alignment. Likewise, a processor's ability to execute an unaligned load does not by itself relax the C programming language's object-access requirements. Keeping the language rule, the application binary interface layout, and the machine instruction separate explains why a byte buffer cannot automatically be treated as a properly located object of any chosen type. Articles by others on the same topic
There are currently no matching articles.