Does C++ support Variable Length Arrays?(C++ 是否支持变长数组?)
问题描述
不,等等,忍受我...
No, wait, bear with me...
VLA 一直是 GCC 的扩展,但它们被 C99 采用:
VLAs were always a GCC extension, but they were adopted by C99:
[C99: 6.7.5.2/4]:
如果大小不存在,则数组类型为不完整的类型.如果大小是 * 而不是表达式,则数组类型是未指定大小的可变长度数组类型,它只能在具有函数原型作用域的声明中使用;这样的数组仍然是完整的类型.如果大小为整数常量表达式并且元素类型具有已知的常量大小,数组类型不是变长数组类型;否则,数组类型是变长数组类型.
[C99: 6.7.5.2/4]:
If the size is not present, the array type is an incomplete type. If the size is * instead of being an expression, the array type is a variable length array type of unspecified size, which can only be used in declarations with function prototype scope; such arrays are nonetheless complete types. If the size is an integer constant expression and the element type has a known constant size, the array type is not a variable length array type; otherwise, the array type is a variable length array type.
C99 也称为 ISO/IEC 9899:1999
.
现在:
[C++11: 1.1/2]:
C++ 是一种基于通用编程语言使用 ISO/IEC 9899:1999 中规定的 C 编程语言(以下简称C标准).除了C 提供的工具,C++ 提供额外的数据类型、类、模板、异常、命名空间、运算符重载、函数名超载、引用、免费的商店管理操作符,以及额外的图书馆设施.
[C++11: 1.1/2]:
C++ is a general purpose programming language based on the C programming language as specified in ISO/IEC 9899:1999 (hereinafter referred to as the C standard). In addition to the facilities provided by C, C++ provides additional data types, classes, templates, exceptions, namespaces, operator overloading, function name overloading, references, free store management operators, and additional library facilities.
那么 C++11 不应该也有 VLA 吗?
推荐答案
这种留有余地的措辞并不意味着 C99 中的所有内容都在 C++11 中.您引用的只是介绍性文字.
That leeway wording doesn't mean that any and everything in C99 is in C++11. What you quoted is just introductory text.
这篇关于C++ 是否支持变长数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 是否支持变长数组?


- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 从python回调到c++的选项 2022-11-16