应该定义和声明是否匹配?
在我.h文件中我有
extern int a[4];
在我的.c文件我有
int a[10];
那么,有没有任何问题,这件事?
So are there any issues with this?
宣言和定义大小事务?不是吧?
Declaration and definition size matters? Not right?
如果我写的的sizeof(A)
中的文件之一,会是怎样的输出?
这是不确定的行为?
If I write sizeof(a)
in one of the files, what will be the output?
Is this undefined behavior?
如果您在您的源代码头文件文件的两个声明 A
必须具有的同的类型为C说:
If you include your header file in your source file the two declarations of a
must have the same type as C says:
(C11,6.7p4)在同一范围内的所有声明指向同一对象或函数应规定兼容的类型。
(C11, 6.7p4) "All declarations in the same scope that refer to the same object or function shall specify compatible types."
即使这两个声明有两种翻译单位,他们需要具备的相同的类型:
Even if the two declarations are in two translation units, they need to have the same type:
(C11,6.2.7p2)是指同一对象或函数的所有声明应具有兼容的类型;否则,其行为是未定义
(C11, 6.2.7p2) "All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined."