T D[N] 是否总是声明数组类型的对象?
Does T D[N] always declare an object of array type?
我对 [dcl.array]/1 感到困惑:
In a declaration T D where D has the form
D1 [ constant-expressionopt ] attribute-specifier-seqopt
and the type of the identifier in the declaration T D1 is “derived-declarator-type-list T”, then the type of the identifier of D is an array type; ...
考虑声明:
int (*p)[42];
这个声明满足上面描述的语法(不满足前面段落描述的语法),所以这个段落应该适用,因此我们断定p
的类型是一个数组类型。但是,我们知道p
的类型是pointer to array of 42 int
,是指针类型
我错过了什么吗?或者pointer to array of 42 int
确实是数组类型?
int (*p)[42];
你说
This declaration satisfies the grammar described above.
从这个角度来看,*p
是一个包含 42 个 int
元素的数组,这是正确的。正好符合 p
的类型。它是指向 "an array of 42 int
s".
的指针
这是标准措辞的错误。当然,int (*p)[42];
不是数组类型,但满足[dcl.array]/1 (and does not satisfy the previous grammars in [dcl.meaning]/5, [dcl.meaning]/6, [dcl.ptr]/1, [dcl.ref]/1 or [dcl.mptr]/1)中的语法,所以[dcl.array]/1应该适用。
我已经发布了 editorial issue。
我对 [dcl.array]/1 感到困惑:
In a declaration T D where D has the form
D1 [ constant-expressionopt ] attribute-specifier-seqopt
and the type of the identifier in the declaration T D1 is “derived-declarator-type-list T”, then the type of the identifier of D is an array type; ...
考虑声明:
int (*p)[42];
这个声明满足上面描述的语法(不满足前面段落描述的语法),所以这个段落应该适用,因此我们断定p
的类型是一个数组类型。但是,我们知道p
的类型是pointer to array of 42 int
,是指针类型
我错过了什么吗?或者pointer to array of 42 int
确实是数组类型?
int (*p)[42];
你说
This declaration satisfies the grammar described above.
从这个角度来看,*p
是一个包含 42 个 int
元素的数组,这是正确的。正好符合 p
的类型。它是指向 "an array of 42 int
s".
这是标准措辞的错误。当然,int (*p)[42];
不是数组类型,但满足[dcl.array]/1 (and does not satisfy the previous grammars in [dcl.meaning]/5, [dcl.meaning]/6, [dcl.ptr]/1, [dcl.ref]/1 or [dcl.mptr]/1)中的语法,所以[dcl.array]/1应该适用。
我已经发布了 editorial issue。