4 ms·
agree -- inability to do variable-sized arrays on the stack is the root of the problem.
by awinter-py 10y ago
agree -- inability to do variable-sized arrays on the stack is the root of the problem.
- dbaupp 10y agoI'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.
- dbaupp 10y agoI'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.
- PeCaN 10y agoThis is what I really like about Ada. Variable-sized arrays and structs on the stack is easy, safe, and efficient in Ada.
- enriquto 10y agoWhat do you mean? Variable-length arrays are OK in C.
- awinter-py 10y agooops -- you're right. https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html Legal in C99, available in C++ on gcc/clang.
- pjmlp 10y agoOptional in C11, not accepted in ANSI C++17.
- pjmlp 10y agoNot in C11, they were removed due to security issues and became an optional language feature.