Structure packing/field alignment



The default layout of Type and Union structures in FreeBASIC is compatible to that of GCC, following the SysV (Linux/BSD) and Microsoft (Windows) ABIs. This allows for binary compatibility with GCC and other compilers.

By default, fields are aligned to their natural boundaries, which are:
The compiler aligns fields by inserting padding bytes in front of them in order to move them to an offset that corresponds to their natural boundary, or to a multiple of the value given with Field = N, if it is smaller than the field's natural alignment. On the x86 architecture, such proper alignment is not required but can result in better performance when accessing the fields. Other architectures might actually require proper alignment.

In addition to field alignment, the whole structure's size is rounded up to a multiple of the largest natural alignment of its fields, by adding padding bytes at the end of the structure. This ensures that in an array of such structures, each individual one is properly aligned as required by the fields.

Back to FreeBASIC Developer Information

Back to Table of Contents
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode