OSDN Git Service

c11efc4455cdbb7bc39f3d388b549fdc9b48effa
[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 .\" 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:
11 .\"
12 .\" The above copyright notice and this permission notice shall be
13 .\" included in all copies or substantial portions of the Software.
14 .\"
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.
22 .\"
23 .\" References:
24 .\"   /usr/lib/gcc/i486-linux-gnu/4.1.1/include/stddef.h
25 .\"   glibc-doc
26 .\"
27 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI
28 .\"                             all rights reserved.
29 .\" Translated 2006-07-25, Akihiro MOTOKI, Catch up to LDP v2.34
30 .\"
31 .TH OFFSETOF 3 2008-07-12 "GNU" "Linux Programmer's Manual"
32 .SH Ì¾Á°
33 offsetof \- ¹½Â¤ÂΤΥá¥ó¥Ð¡¼¤Î¥ª¥Õ¥»¥Ã¥È¤òÊÖ¤¹
34 .SH ½ñ¼°
35 .nf
36 .B #include <stddef.h>
37 .sp
38 .BI "size_t offsetof(" type ", " member );
39 .fi
40 .SH ÀâÌÀ
41 .BR offsetof ()
42 ¥Þ¥¯¥í¤Ï¡¢¥Õ¥£¡¼¥ë¥É \fImember\fP ¤Î
43 ¹½Â¤ÂΠ\fItype\fP ¤ÎÀèƬ¤«¤é¤Î¥ª¥Õ¥»¥Ã¥È¤òÊÖ¤¹¡£
44
45 ¤³¤Î¥Þ¥¯¥í¤¬Í­ÍѤʤΤϡ¢
46 ¹½Â¤ÂΤò¹½À®¤¹¤ë¥Õ¥£¡¼¥ë¥É¤Î¥µ¥¤¥º¤Ï¼ÂÁõ¤Ë¤è¤Ã¤ÆÊѲ½¤¹¤ë¤·¡¢
47 ¥³¥ó¥Ñ¥¤¥é¤Ë¤è¤ê¥Õ¥£¡¼¥ë¥É´Ö¤ËÁÞÆþ¤¹¤ë¥Ñ¥Ç¥£¥ó¥°¤Î¥Ð¥¤¥È¿ô¤â
48 °ã¤¦²ÄǽÀ­¤¬¤¢¤ë¤«¤é¤Ç¤¢¤ë¡£
49 ¤½¤Î·ë²Ì¡¢¤¢¤ë¥¨¥ì¥á¥ó¥È¤Î¥ª¥Õ¥»¥Ã¥È¤Ïɬ¤º¤·¤â¤½¤ì¤è¤êÁ°¤Î
50 ¥¨¥ì¥á¥ó¥È¤Î¥µ¥¤¥º¤Î¹ç·×¤È¤Ï¤Ê¤é¤Ê¤¤¡£
51
52 \fImember\fP ¤¬¥Ð¥¤¥È¶­³¦¤Ë°ÌÃÖ¤·¤Æ¤¤¤Ê¤¤¾ì¹ç
53 (¤¹¤Ê¤ï¤Á¡¢¥Ó¥Ã¥È¥Õ¥£¡¼¥ë¥É¤Î¾ì¹ç) ¤Ë¤Ï¡¢
54 ¥³¥ó¥Ñ¥¤¥é¤Ç¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¡£
55 .SH ÊÖ¤êÃÍ
56 .BR offsetof ()
57 ¤Ï¡¢»ØÄꤵ¤ì¤¿
58 .I member
59 ¤Î»ØÄꤵ¤ì¤¿
60 .I type
61 ¤ÎÃæ¤Ç¤Î¥ª¥Õ¥»¥Ã¥È¤ò¡¢¥Ð¥¤¥Èñ°Ì¤ÇÊÖ¤¹¡£
62 .SH ½àµò
63 C89, C99, POSIX.1-2001.
64 .SH Îã
65 Linux/i386 ¥·¥¹¥Æ¥à¤Ç¡¢
66 .BR gcc (1)
67 ¤Î¥Ç¥Õ¥©¥ë¥È¥ª¥×¥·¥ç¥ó¤Ç
68 ¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿¾ì¹ç¡¢²¼µ­¤Î¥×¥í¥°¥é¥à¤Ï°Ê²¼¤Î¤è¤¦¤Ê½ÐÎϤòÊÖ¤¹¡£
69 .in +4n
70 .nf
71
72 .RB "$" " ./a.out"
73 offsets: i=0; c=4; d=8 a=16
74 sizeof(struct s)=16
75 .fi
76 .nf
77 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
78 \&
79 .nf
80 #include <stddef.h>
81 #include <stdio.h>
82 #include <stdlib.h>
83
84 int
85 main(void)
86 {
87     struct s {
88         int i;
89         char c;
90         double d;
91         char a[];
92     };
93
94     /* ½ÐÎϤϥ³¥ó¥Ñ¥¤¥é°Í¸¤Ç¤¢¤ë */
95
96     printf("offsets: i=%ld; c=%ld; d=%ld a=%ld\\n",
97             (long) offsetof(struct s, i),
98             (long) offsetof(struct s, c),
99             (long) offsetof(struct s, d),
100             (long) offsetof(struct s, a));
101     printf("sizeof(struct s)=%ld\\n", (long) sizeof(struct s));
102
103     exit(EXIT_SUCCESS);
104 }
105 .fi