可变修饰的A型VLA仅是VLA吗?
一个简单的问题:可变修改类型是否仅是 VLA(可变长度数组)?
C11,6.10.8.3 条件特征宏,1(添加强调):
__STDC_NO_VLA__
整数常量1
,旨在指示 实现不支持可变长度数组或可变 修改类型。
这是否意味着除了 VLA 之外还存在可变修改类型?有什么例子吗?
“可变修饰类型”和“可变长度数组”之间有什么关系?
补充:“变长数组”的定义取决于“已知常量大小”的定义:
如果大小是整数常量表达式 并且元素类型具有已知的常量大小,数组类型不是可变长度 数组类型;否则,数组类型为变长数组类型。
然而,“已知常量大小”的定义取决于“可变长度数组”的定义:
如果类型不是不完整且不是可变长度数组类型,则该类型具有已知常量大小。
有点困惑。
相关灾难恢复: http://www.open-std .org/jtc1/sc22/wg14/www/docs/dr_312.htm。
A simple question: is variably-modified type a VLA (variable length array) only?
C11, 6.10.8.3 Conditional feature macros, 1 (emphasis added):
__STDC_NO_VLA__
The integer constant1
, intended to indicate that the
implementation does not support variable length arrays or variably
modified types.
Does it mean that there is a variably-modified type, other than VLA? Any examples?
What is the relationship between "variably modified type" and "variable length array"?
Extra: the definition of "variable length array" depends on the definition of "known constant size":
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.
However, the definition of "known constant size" depends on the definition of "variable length array":
A type has known constant size if the type is not incomplete and is not a variable length array type.
A bit confused.
Related DR: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_312.htm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据C标准(6.7.6宣言者)
这是一个演示程序,
程序输出
在此程序中,指针类型
ptr
定义为int( *)[n]
是一种可变的修改类型。这个报价
意味着,在程序执行过程中,在运行时与运行时的评估相反,在编译时与运行时的评估相反,对此类类型的运算符进行
sizeof
。报价相对于下面的报价具有不同的含义
这说明了如何区分可变长度阵列的声明与声明不变长度阵列的声明。
According to the C Standard (6.7.6 Declarators)
Here is a demonstration program
The program output is
In this program the pointer type
Ptr
defined likeint( * )[n]
is a variably modified type.This quote
means that the
sizeof
operator for such types is evaluated at compile-time opposite to the evaluation at run-time for variable length array types and the size of such a type is not changed during the program execution.The quote has a different meaning relative to the quote below
that says about how distinguish a declaration of a variable length array from a declaration of a non-variable length array.
C 2018 6.7.6 3说:
因此,
int(*)[n]
,对于某些非恒定n
,即使它是指针,也是一种可变的修改类型。此外,int [3] [n]
是一种可变的修改类型。C 2018 6.7.6 3 says:
Therefore
int (*)[n]
, for some non-constantn
, is a variably modified type even though it is a pointer. Further,int [3][n]
is a variably modified type.