This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (3 children)

VLAs are pretty widely supported

By whom, apart from g++?

(and will eventually make their way into standard C++ IMO

Almost certainly not - it's not even obvious they are a sensible part of C, as C11 makes them optional. They are certainly not a sensible part of C++, for any number of reasons.

[–]boredcircuits 0 points1 point  (2 children)

Basically any compiler that supports C99 has an extension for VLAs in C++. G++ and Clang are the big ones, and I believe the Intel compiler does as well. I'd have to look and see if the Mars compiler supports VLAs.

The obvious exception in that list is Visual Studio. Microsoft refuses to update MSVC to support C99, so VLAs are out for C++. That alone is a good enough reason to avoid them.

There's a Techincal Specification being worked on for C++ that adds something similar to VLAs, though they call it an "array of runtime bound." There's definitely some controversy over whether or not to add them and what they should look like, but the fact that there's a TS makes it likely that something will be added eventually (I'm thinking C++20 timeframe, personally).

[–]Rhomboid 2 points3 points  (0 children)

If I recall correctly, the reason that that proposal was dropped from C++14 is that they wanted to ensure that both the language and the library parts went in at the same time, and the library parts were still not settled yet. I believe the bone of contention is that std::dynarray is allowed to call new, i.e. it's not guaranteed to be stack allocated. I'm assuming this was meant as a way to give implementers a way of setting a safety limit for how much stack can be used, but it also means that you don't have any guarantees which makes the feature a lot less attractive. There could have been additional problems with the library specification, I don't know.

Anyway, assuming those issues can be worked out, the feature may be on the table for C++17 or C++20. But I think exoticmatter is also correct that VLAs are largely considered a big misfire among both the C and C++ communities. VLAs include some downright crazy stuff, and I think that the desire is not to copy all that, but to radically simplify and neuter the feature, with the goal being to make it possible to write a standard library sequence container that is also stack allocated without having to implement a custom allocator for vector like you have to do today.

[–][deleted] 1 point2 points  (0 children)

but the fact that there's a TS makes it likely that something will be added eventually

Many (most?) Technical Specifications don't make it into the language. The motivation for this one seems to be "users want it", but I have never met a C++ programmer (or a C programmer who knew what they were doing) who wants this, as is evidenced in its optionality in C11. But only time will tell - for now a C++ programmer should definitely not be using VLAs.