xref: /netbsd-src/share/man/man3/__alignof__.3 (revision 716425e6ac5e8a54bdd8556fde4c7cd98ae2cb54)
1.\" $NetBSD: __alignof__.3,v 1.5 2011/04/14 06:56:28 wiz Exp $
2.\"
3.\" Copyright (c) 2010 Jukka Ruohonen <jruohonen@iki.fi>
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25.\" POSSIBILITY OF SUCH DAMAGE.
26.\"
27.Dd December 20, 2010
28.Dt __ALIGNOF__ 3
29.Os
30.Sh NAME
31.Nm __alignof__
32.Nd GNU extension for alignment of an object
33.Sh SYNOPSIS
34.Ft int
35.Fn __alignof__ "void x"
36.Sh DESCRIPTION
37The
38.Fn __alignof__
39operator returns the alignment of its operand.
40The operand can be a type or an expression.
41If the operand is a
42.Sq lvalue ,
43the return value represents the required alignment of the underlying type,
44not the actual alignment of the specified
45.Sq lvalue .
46.Pp
47The returned value is specific to the architecture and the
48.Tn ABI .
49If the architecture does not impose strict alignment requirements,
50.Fn __alignof__
51returns the minimum required alignment.
52If
53.Xr __aligned 3
54is used to increase the alignment,
55.Fn __alignof__
56returns the specified alignment.
57.Sh EXAMPLES
58The syntax is comparable to the
59.Fn sizeof
60operator.
61If the architecture aligns integers along 32-bit address boundaries,
62the following should print the value 4.
63.Bd -literal -offset indent
64(void)printf("%d\en", __alignof__(int));
65.Ed
66.Pp
67On the other hand, the following example should print the value 1,
68even though this is unlikely to be the actual alignment of the
69structure member.
70.Bd -literal -offset indent
71struct align {
72	int  x;
73	char y;
74} a;
75
76(void)printf("%d\en", __alignof__(a.y));
77.Ed
78.Sh SEE ALSO
79.Xr gcc 1 ,
80.Xr attribute 3 ,
81.Xr offsetof 3 ,
82.Xr typeof 3
83.Sh CAVEATS
84This is a non-standard, compiler-specific extension.
85