1ALLOCA(3)                  Linux Programmer's Manual                 ALLOCA(3)
2
3
4

NAME

6       alloca - memory allocator
7

SYNOPSIS

9       #include <alloca.h>
10
11       void *alloca(size_t size);
12

DESCRIPTION

14       The  alloca() function allocates size bytes of space in the stack frame
15       of the caller.  This temporary space is automatically  freed  when  the
16       function that called alloca() returns to its caller.
17

RETURN VALUE

19       The  alloca()  function returns a pointer to the beginning of the allo‐
20       cated space.  If the allocation causes stack overflow,  program  behav‐
21       iour is undefined.
22

CONFORMING TO

24       There  is  evidence  that  the  alloca() function appeared in 32v, pwb,
25       pwb.2, 3bsd, and 4bsd.  There is a man page for it  in  4.3BSD.   Linux
26       uses the GNU version.  This function is not in POSIX.1-2001.
27

NOTES ON THE GNU VERSION

29       Normally, gcc translates calls to alloca() by inlined code. This is not
30       done when either the -ansi or the -fno-builtin  option  is  given.  But
31       beware!  By default the glibc version of <stdlib.h> includes <alloca.h>
32       and that contains the line
33              # define alloca(size)   __builtin_alloca (size)
34       with messy consequences if one has a private version of this function.
35
36       The fact that the code is inlined, means that it is impossible to  take
37       the  address  of  this  function, or to change its behaviour by linking
38       with a different library.
39
40       The inlined code often consists of a single instruction  adjusting  the
41       stack  pointer,  and does not check for stack overflow.  Thus, there is
42       no NULL error return.
43

BUGS

45       The alloca() function is machine and compiler dependent. On  many  sys‐
46       tems its implementation is buggy. Its use is discouraged.
47
48       On many systems alloca() cannot be used inside the list of arguments of
49       a function call, because the stack space  reserved  by  alloca()  would
50       appear  on  the stack in the middle of the space for the function argu‐
51       ments.
52

SEE ALSO

54       brk(2), pagesize(2), calloc(3), malloc(3), realloc(3)
55
56
57
58GNU                               2002-07-17                         ALLOCA(3)
Impressum