alloca(3C)
_________________________________________________________________
alloca $builtin function
Allocate additional memory from the stack.
_________________________________________________________________
Calling Sequence
char *ptr, *alloca();
unsigned int size;
ptr = alloca(size);
(or)
$builtin char *alloca();
char *ptr;
unsigned int size;
ptr = alloca(size);
where size is the number of bytes to allocate from the stack.
Description
Use the alloca function to allocate additional memory from the
stack. The first calling sequence noted above uses a function
call. The second might generate smaller or faster code, but may
not run under other C compilers.
Unlike other allocation functions, alloca takes memory directly
from the caller's stack. The memory is implicitly returned to
the stack when the routine that called alloca returns to its
caller.
Since hardware representations for pointers to characters differ
from those of pointers to other data types, use a cast operation
to convert the resulting pointer to the correct type.
The include file dglib.h defines the alloca function and uses the
$builtin version.
Returns
The alloca function returns a character pointer to the allocated
memory.
Related Functions
See also the alloc, calloc, malloc, and realloc functions.
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
alloca(3C)
Example
/* Program test for the alloca() function */
#include <stdio.h>
char *ptr, *alloca();
unsigned int size;
main(argc, argv)
int argc;
char *argv[];
{
size = atou(argv[1]);
ptr = alloca(size);
printf("size = %d bytes in the block %o.\n", size, ptr);
}
A call to the program test with an argument of 512 generates the
following output:
size = 512 bytes in the block 34000020424.
The address will vary, depending on the amount of stack used and
the extern/static data.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)