Runtime array bounds on stack as per c++ draft

Daemon :

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”
}
NathanOliver :

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)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=29077&siteId=1