Name
alloca - Allocates bytes from the program's stack.
Syntax
#include <malloc.h>
void *alloca(size)
size_t size;
Description
The alloca routine allocates size bytes from the program's
stack. The allocated space is automatically freed when the
calling function is exited.
When you compile with optimization on (either by default or
by using one of the options), the stack pointer may not be
restored properly in functions that have no local variables
and that also reference the alloca function.
To ensure that the stack pointer is properly restored, you
should make sure that any function that references alloca
declares at least one local variable.
Return Value
The alloca routine returns a void pointer to the allocated
space, which is guaranteed to be suitably aligned for
storage of any type of object. To get a pointer to a type
other than char, use a type cast on the return value. The
return value is NULL if the space cannot be allocated.
See Also
calloc(S), malloc(DOS), realloc(S)
Notes
The pointer value returned by alloca should never be passed
as an argument to free, nor should alloca be used in an
expression that is an argument to a function.
Example
#include <malloc.h>
main() {
int *intarray;
intarray = (int *)alloca(10*sizeof(int)); }
This example calls alloca to allocate enough stack space for
10 integers.
(printed 6/18/89)