Can someone fill me in on why VLAs are a non-feature?
Can someone fill me in on why VLAs are a non-feature?
But even discounting that, there are still some issues with VLAs. For instance, the Linux kernel decided to remove all uses of VLAs they had, because they generate worse code than a partially-used fixed-size buffer, and also make it easier to overflow the kernel stack. VLAs, like their ancestor alloca(), seem convenient but often are more trouble than they're worth.
Can you clarify what you mean by this? It's not clear to me what it would even mean to expose a VLA in the ABI: they are function scoped and as a result it doesn't seem like they could escape to the ABI.
"VLAs as [...] function arguments" sounds like it would just be normal passing of arrays. It's not clear that VLAs have any effect here.
"VLAs as struct members [...]" is still not clearly an ABI issue: if they existed, the types would still be confined to the function they are declared in, and thus would not affect ABI.
That's why we decided to not use them in dav1d.
Additionally gcc and clang are probably the only C compilers that ever bothered to support it.
It may be more accurate to state that "msvc is probably the only C compiler that didn't bother to support it"?
(Though it would be interesting to perform a more complete survey of C compilers to determine how widely supported VLAs are)
But yeah, the real reason is that MSVC will never implement VLAs.
The Linux man page is in fact explicit that it never returns NULL:
RETURN VALUE
The alloca() function returns a pointer to the
beginning of the allocated space. If the
allocation causes stack overflow, program behavior
is undefined.
NOTES
...
The inlined code often consists of a single
instruction adjusting the stack pointer, and
does not check for stack overflow. Thus, there
is no NULL error return.
As a practical matter it is difficult for an implementation to have alloca return an error value even if they wanted to: it would be both two slow and in some cases "impossible" to know ahead of time in the same way that malloc is unlikely to return null on some systems.guard pages are one mechanism for doing that.
IMO, the reality with C is that one needs to be aware of input, whether using VLAs, recursion, or any number of other mechanisms (overflowing calculated values passed to malloc, etc).
It isn't clear that VLAs are a significant departure from what C already provides in the way of unsafety.