In C99, it was legal:
void f(size_t sz) { char arr[sz];
However, these β dynamically sized stack arrays β were flushed in C ++ and did not see a return in C ++ 11.
AFAIK C ++ was made considering compatibility with C, so I wondered. There must be some very good argument not including this useful function, right?
All I could think of was this:
Pros
- Save memory due to a more reasonable array size that should be on the stack (temporary buffers?).
- Less "smart pointers" (or, worse, manually entering
delete [] errors) and slow heap allocations. - Compatible with C99.
Against
- Allows people to easily allocate too large arrays on the stack, which allows overflowing.
- Harder for compilers.
So why didn't they turn it on when they imported other C99 features?
To prevent this from being closed as βsubjectiveβ or βnon-constructive,β I am looking for quotes from community members or links to discussions about this, with bonuses for a quick SO round, of course.
Instead of viewing this as a discussion of Ponies vs Hamsters, treating it as a historical issue, just be interested in the advantages and disadvantages that were considered (if at all).
EDIT . As James McNellis noted in the comments below, C ++ existed before standardized variable length arrays of C99. You could read my question, and then: " Why didn't they add it? "
c ++ stack standards dynamic-arrays
orlp Sep 18 2018-11-11T00: 00Z
source share