.\" $NetBSD: __alignof__.3,v 1.5 2011/04/14 06:56:28 wiz Exp $ .\" .\" Copyright (c) 2010 Jukka Ruohonen .\" All rights reserved. .\" .\" 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 20, 2010 .Dt __ALIGNOF__ 3 .Os .Sh NAME .Nm __alignof__ .Nd GNU extension for alignment of an object .Sh SYNOPSIS .Ft int .Fn __alignof__ "void x" .Sh DESCRIPTION The .Fn __alignof__ operator returns the alignment of its operand. The operand can be a type or an expression. If the operand is a .Sq lvalue , the return value represents the required alignment of the underlying type, not the actual alignment of the specified .Sq lvalue . .Pp The returned value is specific to the architecture and the .Tn ABI . If the architecture does not impose strict alignment requirements, .Fn __alignof__ returns the minimum required alignment. If .Xr __aligned 3 is used to increase the alignment, .Fn __alignof__ returns the specified alignment. .Sh EXAMPLES The syntax is comparable to the .Fn sizeof operator. If the architecture aligns integers along 32-bit address boundaries, the following should print the value 4. .Bd -literal -offset indent (void)printf("%d\en", __alignof__(int)); .Ed .Pp On the other hand, the following example should print the value 1, even though this is unlikely to be the actual alignment of the structure member. .Bd -literal -offset indent struct align { int x; char y; } a; (void)printf("%d\en", __alignof__(a.y)); .Ed .Sh SEE ALSO .Xr gcc 1 , .Xr attribute 3 , .Xr offsetof 3 , .Xr typeof 3 .Sh CAVEATS This is a non-standard, compiler-specific extension.