外部使用指针而不是数组

Extern using pointer instead of array

假设我们有2个文件

1) file1.c

int Appples[10];

2) file2.c

extern int *Appples;

除了我必须独立处理大小之外,这种类型的声明是否有任何问题?

C FAQs 6.1

中对此进行了介绍

The type pointer-to-type-T is not the same as array-of-type-T. Use extern char a[].

this answer 更具体地解决了这个问题。最后一点是:数组不是指针,你不应该这样对待它。

当您将变量声明为:

extern int *Appples;

需要定义为:

int *Appples = <initializer>;

不像:

int Appples[10];

如果要定义使用:

int Appples[10];

可以声明为:

extern int Appples[10];

extern int Appples[];