OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[linuxjm/LDP_man-pages.git] / release / man3 / offsetof.3
1 .\" Copyright (C) 2006 Justin Pryzby <pryzbyj@justinpryzby.com>
2 .\"     and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(PERMISSIVE_MISC)
5 .\" Permission is hereby granted, free of charge, to any person obtaining
6 .\" a copy of this software and associated documentation files (the
7 .\" "Software"), to deal in the Software without restriction, including
8 .\" without limitation the rights to use, copy, modify, merge, publish,
9 .\" distribute, sublicense, and/or sell copies of the Software, and to
10 .\" permit persons to whom the Software is furnished to do so, subject to
11 .\" the following conditions:
12 .\"
13 .\" The above copyright notice and this permission notice shall be
14 .\" included in all copies or substantial portions of the Software.
15 .\"
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 .\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 .\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 .\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 .\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 .\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References:
26 .\"   /usr/lib/gcc/i486-linux-gnu/4.1.1/include/stddef.h
27 .\"   glibc-doc
28 .\"*******************************************************************
29 .\"
30 .\" This file was generated with po4a. Translate the source file.
31 .\"
32 .\"*******************************************************************
33 .TH OFFSETOF 3 2008\-07\-12 GNU "Linux Programmer's Manual"
34 .SH 名前
35 offsetof \- 構造体のメンバーのオフセットを返す
36 .SH 書式
37 .nf
38 \fB#include <stddef.h>\fP
39 .sp
40 \fBsize_t offsetof(\fP\fItype\fP\fB, \fP\fImember\fP\fB);\fP
41 .fi
42 .SH 説明
43 \fBoffsetof\fP()  マクロは、フィールド \fImember\fP の 構造体 \fItype\fP の先頭からのオフセットを返す。
44
45 このマクロが有用なのは、 構造体を構成するフィールドのサイズは実装によって変化するし、 コンパイラによりフィールド間に挿入するパディングのバイト数も
46 違う可能性があるからである。 その結果、あるエレメントのオフセットは必ずしもそれより前の エレメントのサイズの合計とはならない。
47
48 \fImember\fP がバイト境界に位置していない場合 (すなわち、ビットフィールドの場合) には、 コンパイラでエラーが発生する。
49 .SH 返り値
50 \fBoffsetof\fP()  は、指定された \fImember\fP の指定された \fItype\fP の中でのオフセットを、バイト単位で返す。
51 .SH 準拠
52 C89, C99, POSIX.1\-2001.
53 .SH 例
54 Linux/i386 システムで、 \fBgcc\fP(1)  のデフォルトオプションで コンパイルされた場合、下記のプログラムは以下のような出力を返す。
55 .in +4n
56 .nf
57
58 $\fB ./a.out\fP
59 offsets: i=0; c=4; d=8 a=16
60 sizeof(struct s)=16
61 .fi
62 .SS プログラムのソース
63 \&
64 .nf
65 #include <stddef.h>
66 #include <stdio.h>
67 #include <stdlib.h>
68
69 int
70 main(void)
71 {
72     struct s {
73         int i;
74         char c;
75         double d;
76         char a[];
77     };
78
79     /* 出力はコンパイラ依存である */
80
81     printf("offsets: i=%ld; c=%ld; d=%ld a=%ld\en",
82             (long) offsetof(struct s, i),
83             (long) offsetof(struct s, c),
84             (long) offsetof(struct s, d),
85             (long) offsetof(struct s, a));
86     printf("sizeof(struct s)=%ld\en", (long) sizeof(struct s));
87
88     exit(EXIT_SUCCESS);
89 }
90 .fi
91 .SH この文書について
92 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
93 である。プロジェクトの説明とバグ報告に関する情報は
94 http://www.kernel.org/doc/man\-pages/ に書かれている。