Re:C99 doesn't need function bodies, or 'VLAs are Turing com...
by tstanisl on Friday August 05, 2022 @06:19AM
(#32354049)
There are multiple false myths about VLAs.
Please known that VLA is about the typing not about the storage.
The line:
typedef int T[n];
is the essence of VLA-ness, not `int A[n]`. The array of VLA type can have any kind of storage one wants.
It can be stack
T a;
It can be heap
T *a = malloc(sizeof *a);
It can be even infamous alloca()
T *a = alloca(sizeof *a);
Please stop talking about this "VLA is stack-base vector" crap because it means that one does not understand what VLAs are about. I admin that automatic VLAs are pretty much always wrong but this use case is a tiny bit of the realy functionality of VLA types.
VLA were added to language to handle multidimensional arrays.
And the really shine at this task. Even C++ has not good alternative for it. Vector of vectors is a really crappy data structure.
The line:
is the essence of VLA-ness, not `int A[n]`. The array of VLA type can have any kind of storage one wants.It can be stack
It can be heap It can be even infamous alloca() Please stop talking about this "VLA is stack-base vector" crap because it means that one does not understand what VLAs are about. I admin that automatic VLAs are pretty much always wrong but this use case is a tiny bit of the realy functionality of VLA types.VLA were added to language to handle multidimensional arrays.
And the really shine at this task. Even C++ has not good alternative for it. Vector of vectors is a really crappy data structure.
A few examples when working with square matrices:
- allocation on stack
- allocation on heap - indexing - passing to functions: Please show me something as simple, effective, self-documenting and elegant in C++.