What is the meaning of statement below that the declared type shall not be incomplete type

断了今生、忘了曾经 提交于 2020-01-05 03:38:31

问题


The C standard states:

If the declaration of an identifier for an object is a tentative definition and has internal linkage, the declared type shall not be an incomplete type

What does it mean that "the declared type shall not be an incomplete type"?


回答1:


That means you are not allowed to have:

static int arr[]; // This is illegal as per the quoted standard.
int main(void) {}

The array arris tentatively defined and has an incomplete type (lacks information about the size of the object) and also has internal linkage (static says arr has internal linkage).

Whereas the following (at file scope),

int i; // i is tentatively defined. Valid.

int arr[]; // tentative definition & incomplete type. A further definition 
           // of arr can appear elsewhere. If not, it's treated like
           //  int arr[] = {0}; i.e. an array with 1 element.
           // Valid.

are valid.



来源:https://stackoverflow.com/questions/18733204/what-is-the-meaning-of-statement-below-that-the-declared-type-shall-not-be-incom

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