Arrays of variable length in C ++ 14?

n3639 suggested accepting c99 in C ++ 14 (at least for the first dimension.)

But the last thing I could find lists n3639 as:

Features on the first C ++ 14 CD, subsequently deleted with technical specifications

Did it ever turn into a technical specification or was it lost in the hand?

Reason for my question: I noticed this code:

void f(size_t n) { int a[n]; for (size_t i = 0; i < n; ++i) a[i] = 2 * i; sort(a, a + n); } 

This fails to build in Visual Studio 2015 and in gcc (when the -pedantic flag is used.)

Works fine under gcc5.1, but still does n't work for creating in Visual Studio 2015.

Is it just gcc incorrectly supporting variable lengths of the c99 array in C ++ 14, or did it somehow turn into C ++ 14, and Visual Studio 2015 failed to raise it?

EDIT: It looks like gcc has removed support in gcc6.2: http://coliru.stacked-crooked.com/a/303ae1970fa3f5d2

+5
source share
1 answer

First of all, n3639 tried to replace arrays with Runtime Bound (ARB) instead of Variable Length Arrays (VLA). ARBs will support a subset of VLAs that exclude:

  • multidimensional arrays, in which, in addition to the upper level, there is a runtime boundary (by analogy, the new array also does not support this)
  • function declarator syntax changes
  • sizeof(a) - an expression evaluated at runtime returning size a
  • typedef int a[n]; evaluating n and passing it through typedef

In February 2014, in Issakua, Washington, the standard committee voted unanimously to formulate the technical specification for array extensions from n3820 , its original version arose from n3639 and a proposal from Dynarrays .

In May 2014, n4043 and n4050 tried to solve some “problems with half-editing” in the Dynarray and ARB sections of the Technical Specification of array expansion, respectively.

But the standard committee on October 24, 2014, the teleconference led to huge disagreements over language capabilities, implementation options, and the desire for technical extensions to Array Extensions, ultimately describing it as in a state of uncertainty.

The standard committee in May 2015 in Lenex, Kansas , indicated the direction that the technical specification of array extensions would not be accepted into this current form and it is recommended that:

Removing TS of its current content and pending execution of a working sentence [1]

Ultimately, the March 2016 standard committee meeting in Jacksonville, Florida has moved to close the technical specification of array extensions, while confirming that some proposals related to the array are instead focused on the technical specification of library fixed assets. There was a unanimous vote with the 8th strongest supporter, 5 in favor and 6 abstentions.

By the way, the only work related to arrays that is part of the Technical Specification of the Fundamentals of the library is the accounting for the creation of array time via make_array . Bjarne Stroustrup , creator of C ++, waxed eloquent on the topic :

We need arrays with specified time limits and more secure access to such storage "yesterday"

Unfortunately for Dr. Stroustrup, we and the C ++ community as a whole have no plans for the future to resurrect ARB / VLA with C ++ in the simple form of VLA c99.

+9
source

Source: https://habr.com/ru/post/1259834/


All Articles