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

南笙酒味 提交于 2019-12-22 05:10:30

问题


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?


回答1:


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.




回答2:


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".



来源:https://stackoverflow.com/questions/50823601/does-t-dn-always-declare-an-object-of-array-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!