2 .\" Copyright (c) 1980, 1991 Regents of the University of California.
3 .\" All rights reserved.
5 .\" SPDX-License-Identifier: BSD-4-Clause-UC
7 .\" @(#)alloca.3 5.1 (Berkeley) 5/2/91
9 .\" Converted Mon Nov 29 11:05:55 1993 by Rik Faith <faith@cs.unc.edu>
10 .\" Modified Tue Oct 22 23:41:56 1996 by Eric S. Raymond <esr@thyrsus.com>
11 .\" Modified 2002-07-17, aeb
13 .\" Various rewrites and additions (notes on longjmp() and SIGSEGV).
14 .\" Weaken warning against use of alloca() (as per Debian bug 461100).
16 .TH alloca 3 (date) "Linux man-pages (unreleased)"
18 alloca \- allocate memory that is automatically freed
21 .RI ( libc ", " \-lc )
24 .B #include <alloca.h>
26 .BI "void *alloca(size_t " size );
33 bytes of space in the stack frame of the caller.
34 This temporary space is
35 automatically freed when the function that called
37 returns to its caller.
41 function returns a pointer to the beginning of the allocated space.
42 If the allocation causes stack overflow, program behavior is undefined.
44 For an explanation of the terms used in this section, see
52 Interface Attribute Value
55 T} Thread safety MT-Safe
61 This function is not in POSIX.1.
64 originates from PWB and 32V, and appears in all their derivatives.
68 function is machine- and compiler-dependent.
69 Because it allocates from the stack, it's faster than
74 it can also simplify memory deallocation in applications that use
78 Otherwise, its use is discouraged.
80 Because the space allocated by
82 is allocated within the stack frame,
83 that space is automatically freed if the function return
84 is jumped over by a call to
89 The space allocated by
93 automatically deallocated if the pointer that refers to it
94 simply goes out of scope.
103 is a compiler built-in, also known as
104 .BR __builtin_alloca ().
105 By default, modern compilers automatically translate all uses of
107 into the built-in, but this is forbidden if standards conformance is requested
112 is required, lest a symbol dependency be emitted.
116 is a built-in means it is impossible to take its address
117 or to change its behavior by linking with a different library.
119 Variable length arrays (VLAs) are part of the C99 standard,
120 optional since C11, and can be used for a similar purpose.
121 However, they do not port to standard C++, and, being variables,
122 live in their block scope and don't have an allocator-like interface,
123 making them unfit for implementing functionality like
126 Due to the nature of the stack, it is impossible to check if the allocation
127 would overflow the space available, and, hence, neither is indicating an error.
128 (However, the program is likely to receive a
130 signal if it attempts to access unavailable space.)
134 cannot be used inside the list of arguments of a function call, because
135 the stack space reserved by
137 would appear on the stack in the middle of the space for the