Home | History | Annotate | Line # | Download | only in man3
attribute.3 revision 1.4
 $NetBSD: attribute.3,v 1.4 2010/12/16 15:55:41 jruoho Exp $

Copyright (c) 2010 The NetBSD Foundation, Inc.
All rights reserved.

This code is derived from software contributed to The NetBSD Foundation
by Jukka Ruohonen.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

.Dd December 16, 2010 .Dt ATTRIBUTE 3 .Os .Sh NAME .Nm attribute .Nd non-standard GCC extensions .Sh SYNOPSIS n sys/cdefs.h

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.