OSDN Git Service

(split) LDP v3.30, v3.31 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man3 / alloca.3
1 .\" Copyright (c) 1980, 1991 Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)alloca.3    5.1 (Berkeley) 5/2/91
33 .\"
34 .\" Converted Mon Nov 29 11:05:55 1993 by Rik Faith <faith@cs.unc.edu>
35 .\" Modified Tue Oct 22 23:41:56 1996 by Eric S. Raymond <esr@thyrsus.com>
36 .\" Modified 2002-07-17, aeb
37 .\" 2008-01-24, mtk:
38 .\"     Various rewrites and additions (notes on longjmp() and SIGSEGV).
39 .\"     Weaken warning against use of alloca() (as per Debian bug 461100).
40 .\"
41 .\" Japanese Version Copyright (c) 1996 Kentaro OGAWA
42 .\"         all rights reserved.
43 .\" Translated Sat, 13 Jul 1996 22:44:04 +0900
44 .\"         by Kentaro OGAWA <k_ogawa@oyna.cc.muroran-it.ac.jp>
45 .\" Updated & Modified Tue Oct 16 01:01:48 JST 2001
46 .\"         by Yuichi SATO <ysato@mail.sbvl.muroran-it.ac.jp>
47 .\" Updated & Modified Sat Aug 31 04:42:49 JST 2002 by Yuichi SATO
48 .\"
49 .TH ALLOCA 3 2008-01-24 "GNU" "Linux Programmer's Manual"
50 .\"O .SH NAME
51 .SH Ì¾Á°
52 .\"O alloca \- allocate memory that is automatically freed
53 alloca \- ¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤ë
54 .\"O .SH SYNOPSIS
55 .SH ½ñ¼°
56 .B #include <alloca.h>
57 .sp
58 .BI "void *alloca(size_t " size );
59 .\"O .SH DESCRIPTION
60 .SH ÀâÌÀ
61 .\"O The
62 .\"O .BR alloca ()
63 .\"O function allocates
64 .\"O .I size
65 .\"O bytes of space in the stack frame of the caller.
66 .\"O This temporary space is
67 .\"O automatically freed when the function that called
68 .\"O .BR alloca ()
69 .\"O returns to its caller.
70 .BR alloca ()
71 ´Ø¿ô¤Ï¡¢
72 .I size
73 ¥Ð¥¤¥È¤ÎÎΰè¤ò¸Æ½Ð¸µ¤Î¥¹¥¿¥Ã¥¯¡¦¥Õ¥ì¡¼¥à¤Ë³ä¤êÉÕ¤±¤ë¡£
74 ¤³¤Î°ì»þŪ¤ÊÎΰè¤Ï¡¢
75 .BR alloca ()
76 ¤ò¸Æ¤Ó½Ð¤·¤¿´Ø¿ô¤¬¸Æ½Ð¸µ¤ËÊÖ¤ë¤È¤­¤Ë¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¡£
77 .\"O .SH "RETURN VALUE"
78 .SH ÊÖ¤êÃÍ
79 .\"O The
80 .\"O .BR alloca ()
81 .\"O function returns a pointer to the beginning of the allocated space.
82 .\"O If the allocation causes stack overflow, program behavior is undefined.
83 .BR alloca ()
84 ´Ø¿ô¤Ï¡¢³ä¤êÉÕ¤±¤¿Îΰè¤Î»Ï¤Þ¤ê¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
85 ³ä¤êÉÕ¤±¤Ë¤è¤Ã¤Æ¥¹¥¿¥Ã¥¯¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤¬µ¯¤Ã¤¿¾ì¹ç¤Î
86 ¥×¥í¥°¥é¥à¤ÎÆ°ºî¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
87 .\"O .SH "CONFORMING TO"
88 .SH ½àµò
89 .\"O This function is not in POSIX.1-2001.
90 ¤³¤Î´Ø¿ô¤Ï POSIX.1-2001 ¤Ë¤Ï¤Ê¤¤¡£
91
92 .\"O There is evidence that the
93 .\"O .BR alloca ()
94 .\"O function appeared in 32V, PWB, PWB.2, 3BSD, and 4BSD.
95 .\"O There is a man page for it in 4.3BSD.
96 .\"O Linux uses the GNU version.
97 .\"O This function is not in POSIX.1-2001.
98 32V, PWB, PWB.2, 3BSD, 4BSD ¤Ë
99 .BR alloca ()
100 ´Ø¿ô¤¬Åо줷¤¿¾Úµò¤¬¤¢¤ë¡£
101 4.3BSD ¤Ë¤Ï¡¢¥Þ¥Ë¥å¥¢¥ë¥Ú¡¼¥¸¤¬¤¢¤ë¡£
102 Linux ¤Ï¡¢GNU ÈǤò»È¤Ã¤Æ¤¤¤ë¡£
103 ¤³¤Î´Ø¿ô¤Ï POSIX.1-2001 ¤Ë¤Ï¤Ê¤¤¡£
104 .\"O .SH NOTES
105 .SH Ãí°Õ
106 .\"O The
107 .\"O .BR alloca ()
108 .\"O function is machine- and compiler-dependent.
109 .BR alloca ()
110 ´Ø¿ô¤Ï¡¢µ¡¼ï¤È¥³¥ó¥Ñ¥¤¥é¤Ë°Í¸¤¹¤ë¡£
111 .\"O For certain applications,
112 .\"O its use can improve efficiency compared to the use of
113 .\"O .BR malloc (3)
114 .\"O plus
115 .\"O .BR free (3).
116 .\"O In certain cases,
117 .\"O it can also simplify memory deallocation in applications that use
118 .\"O .BR longjmp (3)
119 .\"O or
120 .\"O .BR siglongjmp (3).
121 .\"O Otherwise, its use is discouraged.
122 ÆÃÄê¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢¤³¤Î´Ø¿ô¤ò»È¤¦¤È
123 .BR malloc (3)
124 ¤È
125 .BR free (3)
126 ¤òÁȤ߹ç¤ï¤»¤Æ»È¤Ã¤¿¾ì¹ç¤ËÈæ¤Ù¤Æ¸úΨ¤ò²þÁ±¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
127 ÆÃÄê¤Î¾ì¹ç¤Ç¤Ï¡¢¤³¤Î´Ø¿ô¤ò»È¤¦¤³¤È¤Ç¡¢
128 .BR longjmp (3)
129 ¤ä
130 .BR siglongjmp (3)
131 ¤ò»È¤¦¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Î¥á¥â¥ê¤Î³«Êü¤ò´Êñ¤Ë¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
132 ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ç¤Ï¡¢¤³¤Î´Ø¿ô¤Î»ÈÍѤϿ侩¤µ¤ì¤Ê¤¤¡£
133
134 .\"O Because the space allocated by
135 .\"O .BR alloca ()
136 .\"O is allocated within the stack frame,
137 .\"O that space is automatically freed if the function return
138 .\"O is jumped over by a call to
139 .\"O .BR longjmp (3)
140 .\"O or
141 .\"O .BR siglongjmp (3).
142 .BR alloca ()
143 ¤Ë¤è¤ê³ä¤êÅö¤Æ¤é¤ì¤ë¶õ´Ö¤Ï¥¹¥¿¥Ã¥¯¥Õ¥ì¡¼¥à¤«¤é³ä¤êÅö¤Æ¤é¤ë¤Î¤Ç¡¢
144 ´Ø¿ô¤ÎÌá¤êÀ褬
145 .BR longjmp (3)
146 ¤ä
147 .BR siglongjmp (3)
148 ¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤ê¥¸¥ã¥ó¥×¤·¤¿¾ì¹ç¤Ë¤Ï¡¢
149 ³ä¤êÅö¤Æ¤é¤ì¤¿¶õ´Ö¤Ï¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¡£
150
151 .\"O Do not attempt to
152 .\"O .BR free (3)
153 .\"O space allocated by
154 .\"O .BR alloca ()!
155 .BR alloca ()
156 ¤Ç³ä¤êÅö¤Æ¤é¤ì¤¿¶õ´Ö¤ò
157 .BR free (3)
158 ¤·¤è¤¦¤È¤¹¤ë¤³¤È¤Î¤Ê¤¤¤è¤¦¤Ë¡ª
159 .\"O .SS Notes on the GNU Version
160 .SH Ãí°Õ
161 .SS GNU ÈǤˤĤ¤¤Æ¤ÎÃí°Õ
162 .\"O Normally,
163 .\"O .BR gcc (1)
164 .\"O translates calls to
165 .\"O .BR alloca ()
166 .\"O with inlined code.
167 .\"O This is not done when either the
168 .\"O .IR "\-ansi" ,
169 .\"O .IR "\-std=c89" ,
170 .\"O .IR "\-std=c99" ,
171 .\"O or the
172 .\"O .IR "\-fno\-builtin"
173 .\"O option is given
174 .\"O (and the header
175 .\"O .I <alloca.h>
176 .\"O is not included).
177 .\"O But beware!
178 .\"O By default the glibc version of
179 .\"O .I <stdlib.h>
180 .\"O includes
181 .\"O .I <alloca.h>
182 .\"O and that contains the line:
183 .\"O .nf
184 .\"O 
185 .\"O     #define alloca(size)   __builtin_alloca (size)
186 .\"O 
187 .\"O .fi
188 .\"O with messy consequences if one has a private version of this function.
189 Ä̾ï
190 .BR gcc (1)
191 ¤Ï
192 .BR alloca ()
193 ¤Î¸Æ¤Ó½Ð¤·¤ò¥¤¥ó¥é¥¤¥ó¥³¡¼¥É¤ËÊÑ´¹¤¹¤ë¡£
194 .IR "\-ansi" ,
195 .IR "\-std=c89" ,
196 .IR "\-std=c99" ,
197 .IR "\-fno\-builtin"
198 ¤Î¤¤¤º¤ì¤«¤Î¥ª¥×¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢¤³¤ÎÊÑ´¹¤Ï¹Ô¤ï¤ì¤Ê¤¤
199 (¤Þ¤¿
200 .I <alloca.h>
201 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤â¹Ô¤ï¤ì¤Ê¤¤)¡£
202 ¤À¤À¤·¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï glibc ÈǤÎ
203 .I <stdlib.h>
204 ¤Ï
205 .I <alloca.h>
206 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤ª¤ê¡¢¤³¤ì¤Ë¤Ï°Ê²¼¤Î¹Ô¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤Î¤ÇÃí°Õ¤¹¤ë¤³¤È¡£
207 .nf
208
209     #define alloca(size)   __builtin_alloca (size)
210
211 .fi
212 Æȼ«ÈǤΠ__builtin_alloca (size) ´Ø¿ô¤¬¤¢¤ë¤ÈÌñ²ð¤Ê·ë²Ì¤Ë¤Ê¤ë¡£
213 .LP
214 .\"O The fact that the code is inlined means that it is impossible
215 .\"O to take the address of this function, or to change its behavior
216 .\"O by linking with a different library.
217 ¤³¤Î¥³¡¼¥É¤Ï¥¤¥ó¥é¥¤¥ó²½¤µ¤ì¤Æ¤¤¤ë¤Î¤Ç¡¢
218 ¤³¤Î´Ø¿ô¤Î¥¢¥É¥ì¥¹¤ò¼èÆÀ¤·¤¿¤ê¡¢
219 ¾¤Î¥é¥¤¥Ö¥é¥ê¤ò¥ê¥ó¥¯¤·¤ÆÆ°ºî¤òÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£
220 .LP
221 .\"O The inlined code often consists of a single instruction adjusting
222 .\"O the stack pointer, and does not check for stack overflow.
223 .\"O Thus, there is no NULL error return.
224 Ä̾盧¤Î¥¤¥ó¥é¥¤¥ó¥³¡¼¥É¤Ï¥¹¥¿¥Ã¥¯¥Ý¥¤¥ó¥¿¤ò°ÜÆ°¤¹¤ë
225 1 ¤Ä¤ÎÌ¿Îá (instruction) ¤«¤é¹½À®¤µ¤ì¤Æ¤ª¤ê¡¢
226 ¥¹¥¿¥Ã¥¯¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤ò¥Á¥§¥Ã¥¯¤·¤Ê¤¤¡£
227 ¤è¤Ã¤Æ NULL ¥¨¥é¡¼¤¬ÊÖ¤µ¤ì¤ë¤³¤È¤Ï¤Ê¤¤¡£
228 .\"O .SH BUGS
229 .SH ¥Ð¥°
230 .\"O There is no error indication if the stack frame cannot be extended.
231 .\"O (However, after a failed allocation, the program is likely to receive a
232 .\"O .B SIGSEGV
233 .\"O signal if it attempts to access the unallocated space.)
234 ¥¹¥¿¥Ã¥¯¥Õ¥ì¡¼¥à¤¬³ÈÄ¥¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¡¢¥¨¥é¡¼ÄÌÃΤϹԤï¤ì¤Ê¤¤¡£
235 (¤·¤«¤·¤Ê¤¬¤é¡¢³ä¤êÅö¤Æ¤Ë¼ºÇÔ¤·¤¿¸å¤Ç¡¢¥×¥í¥°¥é¥à¤¬³ä¤êÅö¤Æ¤é¤ì¤Ê¤«¤Ã¤¿
236 ¶õ´Ö¤Ë¥¢¥¯¥»¥¹¤·¤è¤¦¤È¤·¤¿¾ì¹ç¤Ë
237 .B SIGSEGV
238 ¥·¥°¥Ê¥ë¤ò¼õ¿®¤¹¤ë¤³¤È¤À¤í¤¦¡£)
239
240 .\"O On many systems
241 .\"O .BR alloca ()
242 .\"O cannot be used inside the list of arguments of a function call, because
243 .\"O the stack space reserved by
244 .\"O .BR alloca ()
245 .\"O would appear on the stack in the middle of the space for the
246 .\"O function arguments.
247 ¿¤¯¤Î¥·¥¹¥Æ¥à¤Ë¤ª¤¤¤Æ¡¢´Ø¿ô¥³¡¼¥ë¤Î°ú¤­¿ô¤Î¥ê¥¹¥ÈÆâ¤Ç¤Ï
248 .BR alloca ()
249 ¤¬»È¤¨¤Ê¤¤¡£
250 ¤³¤ì¤Ï¡¢
251 .BR alloca ()
252 ¤Ë¤è¤Ã¤ÆͽÌ󤵤ì¤ë¥¹¥¿¥Ã¥¯Îΰ褬¡¢
253 ´Ø¿ô°ú¤­¿ô¤Ë»È¤ï¤ì¤ë¥¹¥¿¥Ã¥¯Îΰè¤ÎÃæ¤Ë¸½¤ì¤Æ¤·¤Þ¤¦¤¿¤á¤Ç¤¢¤ë¡£
254 .\"O .SH "SEE ALSO"
255 .SH ´ØÏ¢¹àÌÜ
256 .BR brk (2),
257 .BR longjmp (3),
258 .BR malloc (3)