1 .\" Copyright (C) 2006 Justin Pryzby <pryzbyj@justinpryzby.com>
2 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" Permission is hereby granted, free of charge, to any person obtaining
5 .\" a copy of this software and associated documentation files (the
6 .\" "Software"), to deal in the Software without restriction, including
7 .\" without limitation the rights to use, copy, modify, merge, publish,
8 .\" distribute, sublicense, and/or sell copies of the Software, and to
9 .\" permit persons to whom the Software is furnished to do so, subject to
10 .\" the following conditions:
12 .\" The above copyright notice and this permission notice shall be
13 .\" included in all copies or substantial portions of the Software.
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 .\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 .\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 .\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 .\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 .\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 .\" /usr/lib/gcc/i486-linux-gnu/4.1.1/include/stddef.h
26 .TH OFFSETOF 3 2008-07-12 "GNU" "Linux Programmer's Manual"
28 offsetof \- offset of a structure member
31 .B #include <stddef.h>
33 .BI "size_t offsetof(" type ", " member );
38 returns the offset of the field
39 \fImember\fP from the start of the structure \fItype\fP.
41 This macro is useful because the sizes of the fields that compose
42 a structure can vary across implementations,
43 and compilers may insert different numbers of padding
45 Consequently, an element's offset is not necessarily
46 given by the sum of the sizes of the previous elements.
48 A compiler error will result if
49 \fImember\fP is not aligned to a byte boundary
50 (i.e., it is a bit field).
53 returns the offset of the given
59 C89, C99, POSIX.1-2001.
61 On a Linux/i386 system, when compiled using the default
63 options, the program below produces the following output:
68 offsets: i=0; c=4; d=8 a=16
88 /* Output is compiler dependent */
90 printf("offsets: i=%ld; c=%ld; d=%ld a=%ld\\n",
91 (long) offsetof(struct s, i),
92 (long) offsetof(struct s, c),
93 (long) offsetof(struct s, d),
94 (long) offsetof(struct s, a));
95 printf("sizeof(struct s)=%ld\\n", (long) sizeof(struct s));
101 .\" FIXME . When one day readdir_r(3) is documented, it should have
102 .\" a SEE ALSO that refers to this page.