alloca() — Allocate storage from the stack

Standards

Standards / Extensions C or C++ Dependencies
  both OS/390 V2R6

Format

#include <stdlib.h>

void *alloca(unsigned int size);

General description

The built-in alloca() function obtains memory from the stack. This eliminates the need for an explicit free() as the memory is freed when the stack is collapsed.

If the alloca() function is unable to obtain the requested storage, control will not return to the caller. Instead the application will terminate due to an out of memory condition (if the reserve stack is available and the caller is not XPLINK), or it will terminate with an abend indicating that storage could not be obtained.

To avoid infringing on the user's name space, this nonstandard function is exposed only when you use the compiler option, LANGLVL(EXTENDED). When you use LANGLVL(EXTENDED) any relevant information in the header is also exposed.

Note: Storage from an alloca() is done after a setjmp() (or any variation thereof) is freed on a longjmp() (or any variation thereof) to an XPLINK-compiled function, and not freed on a longjmp() to a NOXPLINK-compiled function. See the longjmp() family of functions for more details.

Returned value

If successful, alloca() returns the address of the requested storage.

Related information