Section: Linux Programmer's Manual (3)
Return to Main Contents
alloca - memory allocator
void *alloca(size_t size);
bytes of space in the stack frame of the caller. This temporary space is
automatically freed when the function that called
returns to its caller.
function returns a pointer to the beginning of the allocated space.
If the allocation causes stack overflow, program behaviour is undefined.
There is evidence that the
function appeared in 32v, pwb, pwb.2, 3bsd, and 4bsd. There is a man page
for it in 4.3BSD. Linux uses the GNU version.
This function is not in POSIX.1-2001.
NOTES ON THE GNU VERSION
translates calls to
by inlined code. This is not done when either the -ansi or
the -fno-builtin option is given. But beware! By default
the glibc version of
and that contains the line
with messy consequences if one has a private version of this function.
# define alloca(size) __builtin_alloca (size)
The fact that the code is inlined, means that it is impossible
to take the address of this function, or to change its behaviour
by linking with a different library.
The inlined code often consists of a single instruction adjusting
the stack pointer, and does not check for stack overflow.
Thus, there is no NULL error return.
function is machine and compiler dependent. On many systems
its implementation is buggy. Its use is discouraged.
On many systems
cannot be used inside the list of arguments of a function call, because
the stack space reserved by
would appear on the stack in the middle of the space for the
- RETURN VALUE
- CONFORMING TO
- NOTES ON THE GNU VERSION
- SEE ALSO
linux.jgfs.net manual pages