20

Is alloca part of the C++ standard?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Ari
  • 3,460
  • 3
  • 24
  • 31

2 Answers2

31

No. The answer says it all.

24

Not only is it not part of the C++ standard, it is not part of any standard. It's not part of C nor is it part of POSIX. Furthermore, allow me to quote from the Linux man page for alloca(3):

The alloca() function is machine and compiler dependent. On many systems its implementation is buggy. Its use is discouraged.

(emphasis added)

Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
  • What about embedded systems?? – Danijel Oct 18 '19 at 08:56
  • Is there something equivalent to `alloca` (i.e. something that allocates a dynamic amount of memory on the stack) that **is** part of the C standard? – mercury0114 Oct 04 '20 at 20:15
  • @mercury0114 There is C99's variable length arrays that do something a bit similar, although the scope of the allocation is not the same as with `alloca`. – madmann91 Dec 05 '20 at 14:20