Does T D[N] always declare an object of array type

2019-04-28 06:25发布

I'm confused about [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; ...

Consider the declaration:

int (*p)[42];

This declaration satisfies the grammar described above (and does not satisfy the grammar described in previous paragraphs), so this paragraph should apply, thus we conclude that the type of p is an array type. However, we know that the type of p is pointer to array of 42 int, which is a pointer type.

Am I missing something? Or pointer to array of 42 int is indeed an array type?

2条回答
时光不老,我们不散
2楼-- · 2019-04-28 06:36

This is a bug of the wording of the standard. Of course, int (*p)[42]; is not an array type, but satisfies the grammar in [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), so [dcl.array]/1 should apply.

I have posted an editorial issue.

查看更多
叼着烟拽天下
3楼-- · 2019-04-28 06:52
int (*p)[42];

You said

This declaration satisfies the grammar described above.

When seen that way, *p is an array of 42 int elements, which is true. That fits the type of p just right. It is a pointer to "an array of 42 ints".

查看更多
登录 后发表回答