问题
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 arr
is 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