1 .\" Copyright (c) 1980, 1991 Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" @(#)alloca.3 5.1 (Berkeley) 5/2/91
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
38 .\" Various rewrites and additions (notes on longjmp() and SIGSEGV).
39 .\" Weaken warning against use of alloca() (as per Debian bug 461100).
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
49 .TH ALLOCA 3 2008-01-24 "GNU" "Linux Programmer's Manual"
52 .\"O alloca \- allocate memory that is automatically freed
53 alloca \- ¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤ë
56 .B #include <alloca.h>
58 .BI "void *alloca(size_t " size );
63 .\"O function allocates
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
69 .\"O returns to its caller.
73 ¥Ð¥¤¥È¤ÎÎΰè¤ò¸Æ½Ð¸µ¤Î¥¹¥¿¥Ã¥¯¡¦¥Õ¥ì¡¼¥à¤Ë³ä¤êÉÕ¤±¤ë¡£
76 ¤ò¸Æ¤Ó½Ð¤·¤¿´Ø¿ô¤¬¸Æ½Ð¸µ¤ËÊÖ¤ë¤È¤¤Ë¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¡£
77 .\"O .SH "RETURN VALUE"
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.
84 ´Ø¿ô¤Ï¡¢³ä¤êÉÕ¤±¤¿Îΰè¤Î»Ï¤Þ¤ê¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
85 ³ä¤êÉÕ¤±¤Ë¤è¤Ã¤Æ¥¹¥¿¥Ã¥¯¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤¬µ¯¤Ã¤¿¾ì¹ç¤Î
86 ¥×¥í¥°¥é¥à¤ÎÆ°ºî¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
87 .\"O .SH "CONFORMING TO"
89 .\"O This function is not in POSIX.1-2001.
90 ¤³¤Î´Ø¿ô¤Ï POSIX.1-2001 ¤Ë¤Ï¤Ê¤¤¡£
92 .\"O There is evidence that the
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 ¤Ë
100 ´Ø¿ô¤¬Åо줷¤¿¾Úµò¤¬¤¢¤ë¡£
101 4.3BSD ¤Ë¤Ï¡¢¥Þ¥Ë¥å¥¢¥ë¥Ú¡¼¥¸¤¬¤¢¤ë¡£
102 Linux ¤Ï¡¢GNU ÈǤò»È¤Ã¤Æ¤¤¤ë¡£
103 ¤³¤Î´Ø¿ô¤Ï POSIX.1-2001 ¤Ë¤Ï¤Ê¤¤¡£
108 .\"O function is machine- and compiler-dependent.
110 ´Ø¿ô¤Ï¡¢µ¡¼ï¤È¥³¥ó¥Ñ¥¤¥é¤Ë°Í¸¤¹¤ë¡£
111 .\"O For certain applications,
112 .\"O its use can improve efficiency compared to the use of
116 .\"O In certain cases,
117 .\"O it can also simplify memory deallocation in applications that use
120 .\"O .BR siglongjmp (3).
121 .\"O Otherwise, its use is discouraged.
122 ÆÃÄê¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢¤³¤Î´Ø¿ô¤ò»È¤¦¤È
126 ¤òÁȤ߹ç¤ï¤»¤Æ»È¤Ã¤¿¾ì¹ç¤ËÈæ¤Ù¤Æ¸úΨ¤ò²þÁ±¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
127 ÆÃÄê¤Î¾ì¹ç¤Ç¤Ï¡¢¤³¤Î´Ø¿ô¤ò»È¤¦¤³¤È¤Ç¡¢
131 ¤ò»È¤¦¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Î¥á¥â¥ê¤Î³«Êü¤ò´Êñ¤Ë¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
132 ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ç¤Ï¡¢¤³¤Î´Ø¿ô¤Î»ÈÍѤϿ侩¤µ¤ì¤Ê¤¤¡£
134 .\"O Because the space allocated by
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
141 .\"O .BR siglongjmp (3).
143 ¤Ë¤è¤ê³ä¤êÅö¤Æ¤é¤ì¤ë¶õ´Ö¤Ï¥¹¥¿¥Ã¥¯¥Õ¥ì¡¼¥à¤«¤é³ä¤êÅö¤Æ¤é¤ë¤Î¤Ç¡¢
148 ¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤ê¥¸¥ã¥ó¥×¤·¤¿¾ì¹ç¤Ë¤Ï¡¢
149 ³ä¤êÅö¤Æ¤é¤ì¤¿¶õ´Ö¤Ï¼«Æ°Åª¤Ë²òÊü¤µ¤ì¤ë¡£
151 .\"O Do not attempt to
153 .\"O space allocated by
156 ¤Ç³ä¤êÅö¤Æ¤é¤ì¤¿¶õ´Ö¤ò
158 ¤·¤è¤¦¤È¤¹¤ë¤³¤È¤Î¤Ê¤¤¤è¤¦¤Ë¡ª
159 .\"O .SS Notes on the GNU Version
161 .SS GNU ÈǤˤĤ¤¤Æ¤ÎÃí°Õ
164 .\"O translates calls to
166 .\"O with inlined code.
167 .\"O This is not done when either the
169 .\"O .IR "\-std=c89" ,
170 .\"O .IR "\-std=c99" ,
172 .\"O .IR "\-fno\-builtin"
176 .\"O is not included).
178 .\"O By default the glibc version of
182 .\"O and that contains the line:
185 .\"O #define alloca(size) __builtin_alloca (size)
188 .\"O with messy consequences if one has a private version of this function.
193 ¤Î¸Æ¤Ó½Ð¤·¤ò¥¤¥ó¥é¥¤¥ó¥³¡¼¥É¤ËÊÑ´¹¤¹¤ë¡£
198 ¤Î¤¤¤º¤ì¤«¤Î¥ª¥×¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢¤³¤ÎÊÑ´¹¤Ï¹Ô¤ï¤ì¤Ê¤¤
201 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤â¹Ô¤ï¤ì¤Ê¤¤)¡£
202 ¤À¤À¤·¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï glibc ÈǤÎ
206 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤ª¤ê¡¢¤³¤ì¤Ë¤Ï°Ê²¼¤Î¹Ô¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤Î¤ÇÃí°Õ¤¹¤ë¤³¤È¡£
209 #define alloca(size) __builtin_alloca (size)
212 Æȼ«ÈǤΠ__builtin_alloca (size) ´Ø¿ô¤¬¤¢¤ë¤ÈÌñ²ð¤Ê·ë²Ì¤Ë¤Ê¤ë¡£
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 ¾¤Î¥é¥¤¥Ö¥é¥ê¤ò¥ê¥ó¥¯¤·¤ÆÆ°ºî¤òÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ç¤¤Ê¤¤¡£
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 ¥¨¥é¡¼¤¬ÊÖ¤µ¤ì¤ë¤³¤È¤Ï¤Ê¤¤¡£
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
233 .\"O signal if it attempts to access the unallocated space.)
234 ¥¹¥¿¥Ã¥¯¥Õ¥ì¡¼¥à¤¬³ÈÄ¥¤Ç¤¤Ê¤«¤Ã¤¿¾ì¹ç¡¢¥¨¥é¡¼ÄÌÃΤϹԤï¤ì¤Ê¤¤¡£
235 (¤·¤«¤·¤Ê¤¬¤é¡¢³ä¤êÅö¤Æ¤Ë¼ºÇÔ¤·¤¿¸å¤Ç¡¢¥×¥í¥°¥é¥à¤¬³ä¤êÅö¤Æ¤é¤ì¤Ê¤«¤Ã¤¿
236 ¶õ´Ö¤Ë¥¢¥¯¥»¥¹¤·¤è¤¦¤È¤·¤¿¾ì¹ç¤Ë
238 ¥·¥°¥Ê¥ë¤ò¼õ¿®¤¹¤ë¤³¤È¤À¤í¤¦¡£)
242 .\"O cannot be used inside the list of arguments of a function call, because
243 .\"O the stack space reserved by
245 .\"O would appear on the stack in the middle of the space for the
246 .\"O function arguments.
247 ¿¤¯¤Î¥·¥¹¥Æ¥à¤Ë¤ª¤¤¤Æ¡¢´Ø¿ô¥³¡¼¥ë¤Î°ú¤¿ô¤Î¥ê¥¹¥ÈÆâ¤Ç¤Ï
252 ¤Ë¤è¤Ã¤ÆͽÌ󤵤ì¤ë¥¹¥¿¥Ã¥¯Îΰ褬¡¢
253 ´Ø¿ô°ú¤¿ô¤Ë»È¤ï¤ì¤ë¥¹¥¿¥Ã¥¯Îΰè¤ÎÃæ¤Ë¸½¤ì¤Æ¤·¤Þ¤¦¤¿¤á¤Ç¤¢¤ë¡£