3 ms·
Object alignment in C is implementation-defined. gcc generally defers to the ABI: https://gcc.gnu.org/onlinedocs/gcc/Architecture-implementation.html#Architectu
by tom_ 8y ago
Object alignment in C is implementation-defined. gcc generally defers to the ABI: https://gcc.gnu.org/onlinedocs/gcc/Architecture-implementation.html#Architecture-implementation https://gcc.gnu.org/onlinedocs/gcc/Architecture-implementati... - note that 2^0 is a valid alignment.
The System V ABI appears to explicitly allow so-called misaligned pointer dereferences, which makes sense as misalignment is, in general, not really a big issue on x86:
"Compilers should allocate independent data objects with the proper alignment ... However, some language facilities (such as FORTRAN EQUIVALENCE statements) may create objects with only byte align- ment. Consequently, arbitrary data accesses, such as pointers dereference or refer- ence arguments, might or might not be properly aligned. Accessing misaligned data will be slower than accessing properly aligned data, but otherwise there is no difference."
Similar wording permits it for x86-64:
"Like the Intel386 architecture, the AMD64 architecture in general does not re- quire all data accesses to be properly aligned. Misaligned data accesses are slower than aligned accesses but otherwise behave identically. The only exceptions are that __m128 and __m256 must always be aligned properly."
The Windows x64 ABI has suggested alignments for max performance but appears to allow anything.
"Although the access of data can stem from any alignment, it is recommended that data be aligned on its natural boundary to avoid performance loss (or a multiple thereof)."