2

As per my understanding based on previous readings, array size needs to be constant and known at compile time with exception to additional support provided by g++ where VLA are supported.

However I was going through one of the c++ draft and now I am confused, does c++ support runtime array bounds. They have given the below code example for defining the array.

C++ draft link: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3690.pdf

Section 8.3.4

Eg:

void f(unsigned int n) {
int a[n]; // type of a is “array of runtime bound of int”
}
Daemon
  • 1,575
  • 1
  • 17
  • 37
  • 3
    Don't refer to outdated standard drafts. The closest drafts to the published standards can be found on [cppreference](https://en.cppreference.com/w/cpp/links) or [in this question](https://stackoverflow.com/questions/81656/where-do-i-find-the-current-c-or-c-standard-documents). – walnut Mar 06 '20 at 15:14

1 Answers1

4

No, C++ has not and still doesn't support arrays with a run time size. N3690 was a draft between C++11 and C++14 and it included the text from the propsal N3639 Runtime-sized arrays with automatic storage duration (revision 5)

That proposal was eventually scrapped and in the C++14 draft N4140 the text was removed.

When looking through the drafts, the ones that you can use as "The standard" are

  • N3337 (C++11 + editorial fixes)
  • N4140 (C++14 + editorial fixes)
  • N4659 (March 2017 post-Kona working draft/C++17 DIS)
NathanOliver
  • 171,901
  • 28
  • 288
  • 402