HP OpenVMS Systems

ask the wizard
Content starts here

Compaq C and OpenVMS Stack Operations?

» close window

The Question is:

I recently posted a question asking why a function to dynamically allocate
 memory on the stack does not exist in OpenVMS. I have since learned that such
 a function exist in Linux (and therefore likely also in Unix). It's name is
 alloca(). Why was this fun
ction excluded when calloc(), malloc() and realloc() were ported?
Thank you very much.

The Answer is :

  The alloca() call is a compiler extension, and is not part of
  the ANSI C standards.
  The calloc(), malloc() and realloc() calls are native code,
  using the OpenVMS Run-time library.  These calls are not ports.
  The alloca() call is a compiler-generated run-time routine, and
  not a subroutine call, and not a run-time library routine.
  A subroutine call cannot alter the stack pointer of a caller.
  Modifications made to the stack or to the stack pointer from within
  the context of the subroutine itself are automatically removed --
  which is what you seek to have happen here -- when the subroutine
  exits.  This means that the alloca() call cannot exist and operate
  as a standard subroutine.
  Various extensions to C standards available within the Compaq C
  compiler -- including a call to allocate stack storage -- are
  documented in the C documentation set.  In this particular case,
  please see the Compaq C User documentation available at the Compaq
  website.  (Pointers to the Compaq language compiler documentation
  are included in the OpenVMS FAQ.)
  Also see topic (6809).

answer written or last revised on ( 30-JUL-2001 )

» close window