It's well-known that VLA is a kind of array implemented besed on WM, which can determine size at runtime. But that's what I all know about it. Now I want to know whether I should use it.
C99 firstly made VLA becomes a part of standard, but then in C11, standard permitted that complier can choose not to support VLA or VM if `#define __STDC_NO_VLA__ 1`, and C++ never bring VLAs into standard, even it hasn't come into TS. I want to find out why the situation is like that.
And here are some opinions(some are mine, some are others), if they are wrong, please point out for me, thank you.
1. It is redundant to use VLA.
> Each time the flow of control passes over the declaration, expression is evaluated (and it must always evaluate to a value greater than zero), and the array is allocated (correspondingly, lifetime of a VLA ends when the declaration goes out of scope). The size of each VLA instance does not change during its lifetime, but on another pass over the same code, it may be allocated with a different size.
If so, then if I use code like this, what is the difference except the *type*?:
Allocate some dynamic memory, and let pointer pt points to the first "element"
dosomething
free the memory allocated
By this way, I can subscript pt and easily modify the value. Except I cannot pass it to an array reference, it seems no differences at all.
2. VLA's performance is too bad.
This isn't my opinion but many people says that. But in fact I don't agree. I don't think it will takes more time than use "dynamic array".
3. VM is just too hard or too haze to implement.
Many semantics( or I'd say feature) should require complie-time evaluated expression, but VM can't implement that, so I think it could be too hard to define the behaviors.
4. C++ has `std::vector`, I think it will be more comfortable to use `vector` than use VLA.
In consequence, many people don't like VLA, but I did have seen someone likes it, so I the answer I want is your attitude t
C99 firstly made VLA becomes a part of standard, but then in C11, standard permitted that complier can choose not to support VLA or VM if `#define __STDC_NO_VLA__ 1`, and C++ never bring VLAs into standard, even it hasn't come into TS. I want to find out why the situation is like that.
And here are some opinions(some are mine, some are others), if they are wrong, please point out for me, thank you.
1. It is redundant to use VLA.
> Each time the flow of control passes over the declaration, expression is evaluated (and it must always evaluate to a value greater than zero), and the array is allocated (correspondingly, lifetime of a VLA ends when the declaration goes out of scope). The size of each VLA instance does not change during its lifetime, but on another pass over the same code, it may be allocated with a different size.
If so, then if I use code like this, what is the difference except the *type*?:
Allocate some dynamic memory, and let pointer pt points to the first "element"
dosomething
free the memory allocated
By this way, I can subscript pt and easily modify the value. Except I cannot pass it to an array reference, it seems no differences at all.
2. VLA's performance is too bad.
This isn't my opinion but many people says that. But in fact I don't agree. I don't think it will takes more time than use "dynamic array".
3. VM is just too hard or too haze to implement.
Many semantics( or I'd say feature) should require complie-time evaluated expression, but VM can't implement that, so I think it could be too hard to define the behaviors.
4. C++ has `std::vector`, I think it will be more comfortable to use `vector` than use VLA.
In consequence, many people don't like VLA, but I did have seen someone likes it, so I the answer I want is your attitude t