You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and the type of the contained declarator-id in the declaration TD1 is “derived-declarator-type-list T”, the type of the declarator-id in D is “derived-declarator-type-list array of NT”. The constant-expression shall be a converted constant expression of type std::size_t ([expr.const]). Its value N specifies the array bound, i.e., the number of elements in the array; N shall be greater than zero.
您好。偶然看到您的这一仓库,发现您的 C++数组长度可以为变量吗? 文章中提出了错误的观点。我在这里郑重地告知您:C++ 不支持变量长度数组(VLA)。
简单来说,VLA 是 C 语言的语法,于 1999 年在 C99 标准中引入(并在 2011 年的 C11 中又取消)。但 C++ 直至目前不支持任何 VLA 相关语法。容易引起误会的是,GCC 和 Clang++ 编译器提供了包含 VLA 的GNU 扩展语法,并且默认引入这些扩展。因此,VLA 在这些 C++ 编译器下可行。反之,如果关闭这些扩展(通过添加
-pedantic-errors
选项)或者非 GNU 兼容的编译器(如 MSVC),则 VLA 不可用。实例测试
GCC 在严格模式下禁止 C++ VLA
Clang++ 在严格模式下禁止 C++ VLA
MSVC 在任何情形下都不允许 C++ VLA
标准文本
取自 C++ 最新标准草案 [dcl.array] 第一段。
其中,注意加粗的文本:(上述语法形式方括号内的)constant-expression 需要是一个经转换后类型为
std::size_t
的常量表达式。The text was updated successfully, but these errors were encountered: