3 ms·
> There is no way to recover from a failed VLA allocation. There's no way to recover from any stack allocation. #define TOO_BIG 1000000 This: {
by _kst_ 11y ago
> There is no way to recover from a failed VLA allocation.
There's no way to recover from any stack allocation.
#define TOO_BIG 1000000
This:
{
double big_array[TOO_BIG]; // not a VLA
}
is no safer than this:
{
size_t size = TOO_BIG; // size is not a constant
double big_vla[size];
}
If you use VLAs (variable length arrays) in a manner that permits arbitrary unchecked sizes, then yes, they're dangerous. If you carefully check the size so that a VLA is no bigger than a corresponding fixed-size array would have been, they don't introduce any new risk.
(I'm not sure why VLAs were made optional in C11, at least for hosted implementations. Support for them was mandatory in C99, and I'm skeptical that they impose any significant burden on compilers.)
- julian-klode 11y agoMicrosoft did not implement them in Visual C and wanted to claim C11 conformity without doing the work, so they bullied it out.