Re:Getting Past C
by awinter-py on Tuesday January 03, 2017 @09:24PM
(#13315180)
agree -- inability to do variable-sized arrays on the stack is the root of the problem.
[ Parent
| on HN ]
I'm not even talking about variably sized arrays, just creating a statically sized one and passing it into functions that take dynamically-sized one. For instance, a read function that fills an existing buffer doesn't care if the buffer is on the heap or on the stack, it only cares that it doesn't overrun the bounds.
alloca-style variable arrays is a whole other can of worms of danger and complexity.
What do you mean? Variable-length arrays are OK in C.
Not in C11, they were removed due to security issues and became an optional language feature.
Re:Getting Past C
by awinter-py on Wednesday January 04, 2017 @07:48AM
(#13317782)
oops -- you're right.
https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
Legal in C99, available in C++ on gcc/clang.
Optional in C11, not accepted in ANSI C++17.