Search code examples
portabilitylibcalloca

What does alloca(0) do and return on various platforms?


Does alloca() returns NULL if the size given is 0?

A quick search reveals that alloca(0) force garbage collection in some cases! but I am mostly interested by return value.

thanks


Solution

  • According to Linux man pages

    Conforming to

    This function is not in POSIX.1-2001.

    Notes

    The alloca() function is machine- and compiler-dependent.

    So alloca()ing 0 size elements is not legal but not defined

    I don't have a specifical example of the return value when size=0. Please, take a look at this question and "Notes on the GNU Version" at the first link