Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <malloc.h>
    void *alloca( size_t size );

Description:
    The alloca function allocates 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.

Returns:
    The alloca function returns a pointer to the start of the allocated
    memory.  The return value is NULL if there is insufficient stack space
    available.

See Also:
    calloc Functions, malloc Functions, stackavail

Example:
    #include <stdio.h>
    #include <string.h>
    #include <malloc.h>
    FILE *open_err_file( char * );

    void main()
      {
        FILE *fp;

        fp = open_err_file( "alloca" );
        if( fp == NULL ) {
          printf( "Unable to open error file\n" );
        } else {
          fclose( fp );
        }
      }

    FILE *open_err_file( char *name )
      {
         char *buffer;
         /* allocate temp buffer for file name */
         buffer = (char *) alloca( strlen(name) + 5 );
         if( buffer ) {
           sprintf( buffer, "%s.err", name );
           return( fopen( buffer, "w" ) );
         }
         return( (FILE *) NULL );
      }

Classification:
    WATCOM

Systems:
    MACRO

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson