Is it required that a C Variable Length Array is allocated from the stack?

There is no requirement that VLAs be allocated from the stack (the language standard doesn’t even mention stacks or heaps). The only requirement is as follows:

6.2.4 Storage durations of objects

7 For such an object that does have a variable length array type, its lifetime extends from
the declaration of the object until execution of the program leaves the scope of the
declaration.35) If the scope is entered recursively, a new instance of the object is created
each time. The initial value of the object is indeterminate.


35) Leaving the innermost block containing the declaration, or jumping to a point in that block or an
embedded block prior to the declaration, leaves the scope of the declaration.

Given this, it makes sense to allocate from the stack, but for very large objects this may not be possible, and such an object may be allocated from the heap or some other memory segment instead. The bookkeeping is up to the implementation.

Leave a Comment