出于某种原因,即使我使用了标头保护,我也会在我的头文件中获得多个内容声明。我的示例代码如下:
主.c:
#include "thing.h"
int main(){
printf("%d", increment());
return 0;
}
东西.c:
#include "thing.h"
int increment(){
return something++;
}
东西.h:
#ifndef THING_H_
#define THING_H_
#include <stdio.h>
int something = 0;
int increment();
#endif
当我尝试编译它时,GCC 说我对 something 变量有多个定义。ifndef 应该确保不会发生这种情况,所以我很困惑为什么会这样。