p c __packed
p .Fn __aligned "x" .Fn __section "section" .Sh DESCRIPTION The .Tn GNU Compiler Collection
q Tn GCC provides many extensions to the standard C language. Among these are the so-called attributes. In .Nx all attributes are provided in a restricted namespace. The described macros should be preferred instead of using the .Tn GCC's .Em __attribute__ extension directly. .Sh FUNCTIONS l -tag -width abc t Ic __packed The c __packed macro expands to an attribute that forces a variable or structure field to have the smallest possible alignment, potentially disregarding architecture specific alignment requirements. The smallest possible alignment is effectively one byte for variables and one bit for fields. If specified on a .Vt struct or .Vt union , all variables therein are also packed. The c __packed macro is often useful when dealing with data that is in a particular static format on the disk, wire, or memory. t Fn __aligned "x" The .Fn __aligned macro expands to an attribute that specifies the minimum alignment in bytes for a variable, structure field, or function. In other words, the specified object should have an alignment of at least .Fa x bytes, as opposed to the minimum alignment requirements dictated by the architecture and the .Tn ABI . Possible use cases include: l -bullet -offset indent t Mixing assembly and C code. t Dealing with hardware that may impose alignment requirements greater than the architecture itself. t Using instructions that may impose special alignment requirements. Typical example would be alignment of frequently used objects along processor cache lines. .El
p Note that when used with functions, structures, or structure members, .Fn __aligned can only be used to increase the alignment. If the macro is however used as part of a .Vt typedef , the alignment can both increase and decrease. Otherwise it is only possible to decrease the alignment for variables and fields by using the c __packed macro. The effectiveness of .Fn __aligned is largely dependent on the linker. t Fn __section "section" The .Fn __section macro expands to an attribute that specifies a particular .Fa section to which a variable or function should be placed. Normally the compiler places the generated objects to sections such as .Dq data or .Dq text . By using .Fn __section , it is possible to override this behavior, perhaps in order to place some variables into particular sections specific to unique hardware. Generally the use cases of .Fn __section are very limited. .El .Sh SEE ALSO .Xr gcc 1 , .Xr cdefs 3 , .Xr c 7 .Sh CAVEATS It goes without saying that portable applications should steer clear from non-standard extensions specific to any given compiler. Even when portability is not a concern, use these macros sparsely and wisely.