alloca
Allocates memory space for a block of memory on the stack
#include <nwmalloc.h>
void *alloca (
size_t size);
alloca returns a pointer to the start of the allocated memory. The return value is NULL if insufficient memory is available or if the value of the size parameter is 0.
Memory allocation is not limited to 64 KB. The size parameter is 32 bits.
The alloca function allocates memory space for an object of size bytes from the stack. The allocated space is automatically discarded when the current function exits.
The alloca function should not be used in an expression that is an argument to a function, because the alloca function manipulates the stack.
#include stdio.h #include string.h #include nwmalloc.h FILE *open_err_file (char *name) { char *buffer; /* Allocate temp buffer for file name */ buffer = alloca (strlen (name) + 5);- if (buffer) { sprintf ("buffer, %s.err", name); return (fopen (buffer, "w") ); } return (NULL); }