]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/alloca.3
Import of man-pages 1.70
[thirdparty/man-pages.git] / 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 .\"
38 .TH ALLOCA 3 2002-07-17 "GNU" "Linux Programmer's Manual"
39 .SH NAME
40 alloca \- memory allocator
41 .SH SYNOPSIS
42 .B #include <alloca.h>
43 .sp
44 .BI "void *alloca(size_t " size );
45 .SH DESCRIPTION
46 The
47 .B alloca
48 function allocates
49 .I size
50 bytes of space in the stack frame of the caller. This temporary space is
51 automatically freed when the function that called
52 .B alloca
53 returns to its caller.
54 .SH "RETURN VALUE"
55 The
56 .B alloca
57 function returns a pointer to the beginning of the allocated space.
58 If the allocation causes stack overflow, program behaviour is undefined.
59 .SH "CONFORMING TO"
60 There is evidence that the
61 .B alloca
62 function appeared in 32v, pwb, pwb.2, 3bsd, and 4bsd. There is a man page
63 for it in BSD 4.3. Linux uses the GNU version.
64 This function is not in POSIX or SUSv3.
65 .SH "NOTES ON THE GNU VERSION"
66 Normally,
67 .B gcc
68 translates calls to
69 .B alloca
70 by inlined code. This is not done when either the \-ansi or
71 the \-fno\-builtin option is given. But beware! By default
72 the glibc version of
73 .I <stdlib.h>
74 includes
75 .I <alloca.h>
76 and that contains the line
77 .RS
78 # define alloca(size) __builtin_alloca (size)
79 .RE
80 with messy consequences if one has a private version of this function.
81 .LP
82 The fact that the code is inlined, means that it is impossible
83 to take the address of this function, or to change its behaviour
84 by linking with a different library.
85 .LP
86 The inlined code often consists of a single instruction adjusting
87 the stack pointer, and does not check for stack overflow.
88 Thus, there is no NULL error return.
89 .SH BUGS
90 The
91 .B alloca
92 function is machine and compiler dependent. On many systems
93 its implementation is buggy. Its use is discouraged.
94 .LP
95 On many systems
96 .B alloca
97 cannot be used inside the list of arguments of a function call, because
98 the stack space reserved by
99 .B alloca
100 would appear on the stack in the middle of the space for the
101 function arguments.
102 .SH "SEE ALSO"
103 .BR brk (2),
104 .BR pagesize (2),
105 .BR calloc (3),
106 .BR malloc (3),
107 .BR realloc (3)