c - 下面声明的类型不应是不完整类型的声明是什么意思

标签 c definition linkage

C 标准规定:

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

“声明的类型不应是不完整的类型”是什么意思?

最佳答案

这意味着您不能拥有:

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

数组 arr 是暂时定义的,类型不完整(缺少关于对象大小的信息),也有内部链接(staticarr 有内部链接)。

鉴于以下(在文件范围内),

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.

有效。

关于c - 下面声明的类型不应是不完整类型的声明是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18733204/

相关文章:

c - 未定义对 `__time32` ncurses 的引用

c++ - 通过单个渲染调用写入渲染缓冲区并使用 OpenGL 显示

c++ - "multiple definition of..."模板函数的完全特化错误

c - 如何在 C 中定义函数数组

function - 正式调用的函数的第一行是什么?

c++ - 错误 LNK2019 : unresolved external symbol in a multiple projects solution

c - 为什么 C 中可以有一个指向字符串数组的指针

c - C 中的 else if 语句未按预期工作

c - 将函数指针传递给静态函数是否可能/安全/理智?

c++ - C++ 中的外部链接