C ++ 14中的可变长度数组? [英] Variable Length Arrays in C++14?

查看:115
本文介绍了C ++ 14中的可变长度数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

n3639 建议采用

我最新能够找到将n3639列出为:

But the latest I've been able to find lists n3639 as:

C ++ 14的第一张CD中的功能,随后被删除为技术规范

Features in the first CD of C++14, subsequently removed to a Technical Specification

这是否使它成为了技术规范,还是在传递中丢失了?

Did this ever make it into a Technical Specification, or was it lost in the hand off?

我的问题的原因是,我注意到以下代码:

The reason for my question is, I've 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);
}

这无法在Visual Studio 2015和gcc(使用"-pedantic"标志的情况下)中构建.

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

工作正常,但仍然这仅仅是gcc在C ++ 14中错误地支持c99的可变长度数组吗,还是因为某种原因使它进入了C ++ 14,而Visual Studio 2015却无法使用它?

Is this just gcc incorrectly supporting c99's Variable Length Arrays in C++14 or did this somehow make it into C++14 and Visual Studio 2015 failed to pick it up?

编辑:看来gcc已删除了gcc6.2中的支持: http://coliru.stacked-crooked.com/a/303ae1970fa3f5d2

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

推荐答案

首先,

First of all, n3639 was looking to put in place Arrays with Runtime Bound (ARB) not Variable Length Arrays (VLA). ARBs would support a subset of VLAs which excluded:

  • 多维数组,其中除顶层以外还具有运行时绑定(类推,array-new不支持该条件)
  • 对函数声明符语法的修改
  • sizeof(a)是运行时评估的表达式,返回a
  • 的大小
  • typedef int a[n];评估n并将其传递给typedef
  • multidimensional arrays, where other than the top level has a runtime bound (in analogy, array-new doesn't support that either)
  • modifications to the function declarator syntax
  • sizeof(a) being a runtime-evaluated expression returning the size of a
  • typedef int a[n]; evaluating n and passing that through the typedef

2014年2月,在华盛顿州伊萨夸,标准委员会一致投票,以形成

In February of 2014 in Issaquah, Washington, at the standard committee unanimously voted to form the Array Extensions Technical Specification from n3820, it's initial revision originated from n3639 and the proposal of Dynarrays.

2014年5月 n4043 和<一个href ="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4050.html" rel ="noreferrer"> n4050 试图解决一些半阵列扩展技术规范的Dynarray和ARB部分中的编辑问题".

In May 2014 n4043 and n4050 attempted to address some "semi-editorial issues" in the Dynarray and ARB sections of the Array Extension Technical Specification, respectively.

但是标准委员会2014年10月24日的电话会议引用了有关语言设施,实现可能性以及对Array Extensions Technical Specification的渴望的巨大分歧,最终将其描述为处于困境.

But the standard committee's October 24 2014 teleconference cited huge disagreement on the language facilities, implementation possibilities, and desire for Array Extensions Technical Specification, ultimately describing it as in a state of limbo.

标准委员会2015年5月在Lenexa举行的会议,堪萨斯州继续提供了方向性指导,以当前形式不接受《阵列扩展技术规范》,并建议:

The standard committee's May 2015 meeting in Lenexa, Kansas went on to give the directional guidance that the Array Extensions Technical Specification would not be accepted in it's current form, and recommended:

剥离其当前内容的TS,并等待提出可行的建议

Stripping the TS of its current contents, and waiting for a workable proposal to come along[1]

最终标准委员会2016年3月的会议佛罗里达杰克逊维尔在确认某些与阵列有关的提案针对的是图书馆基础技术规范后,决定关闭阵列扩展技术规范.进行了一致投票强烈支持8项,赞成5项,弃权6项.

Ultimately the standard committee's March 2016 meeting in Jacksonville, Florida moved to close the Array Extensions Technical Specification at the confirmation that some array-related proposals are targeting the Library Fundamentals Technical Specification instead. There was a unanimous vote to do so with 8 strongly in favor, 5 in favor, and 6 abstaining.

顺便说一句,进入图书馆基础技术规范的唯一与阵列相关的工作是允许通过 Bjarne Stroustrup

Incidentally the only array related work going into the Library Fundamentals Technical Specification is the allowance of run-time creation of an array via make_array. Bjarne Stroustrup, the creator of C++, waxed eloquent on the topic:

我们需要具有运行时指定范围的数组,并在昨天"更安全地访问此类存储

We need arrays with run-time-specified bounds and safer access to such storage "yesterday"

可悲的是,对于Stroustrup博士,我们以及整个C ++社区,将来没有计划以简单的c99 VLA形式用C ++复活ARB/VLA.

Sadly, for Dr. Stroustrup, us, and the C++ community as a whole, there are no future plans to resurrect ARBs/VLAs with C++ in the simple c99 VLA form.

这篇关于C ++ 14中的可变长度数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆