为什么这个冲突的类型声明?

时间:2013-04-02 15:57:34

标签: c

我有如下编译问题。标题文件abc.h包含在abc.c中。

在头文件中,我有这个

extern char **foo;

在源文件中,我有这个

char *foo[] = { ".mp3", ".mp4" };

然而我收到GCC的编译错误:

abc.c:23:7: error: conflicting types for ‘foo’
In file included from abc.c:18:0:
abc.h:64:15: note: previous declaration of ‘foo’ was here

为什么我会收到此错误?

2 个答案:

答案 0 :(得分:5)

一个是指针数组,另一个是指针指针。非常不同的对象。尝试将其声明为数组:

extern char *foo[];

答案 1 :(得分:0)

extern char[]extern char *是两种不同的

对于 extern 声明应该与一个定义匹配。

extern char **foo;

<强>匹配

char **foo;

不匹配

char *foo[];

同样的事情

extern char *foo[];  /* matches */  
char *foo[];