Why is the use of alloca() not considered good practice?

前端 未结 22 2909
甜味超标
甜味超标 2020-11-22 03:00

alloca() allocates memory on the stack rather than on the heap, as in the case of malloc(). So, when I return from the routine the memory is freed.

22条回答
  •  深忆病人
    2020-11-22 03:23

    As noted in this newsgroup posting, there are a few reasons why using alloca can be considered difficult and dangerous:

    • Not all compilers support alloca.
    • Some compilers interpret the intended behaviour of alloca differently, so portability is not guaranteed even between compilers that support it.
    • Some implementations are buggy.

提交回复
热议问题