读书人

条件编译的有关问题

发布时间: 2012-02-07 17:45:36 作者: rapoo

条件编译的问题
//test.c

#include "test.h "


//main.c

#include "test.h "

int main(){
return 0;
}


//test.h

#ifndef test_h
#define test_h

int a;

#endif

问题是为什么编译时还会出现重复定义的错误?
我的用法上有什么错误吗?


[解决办法]
"两个 C文件是先各自编译成 obj 文件,再 link 在一起的。 "

#ifdef等这些东西,在词法分析前就处理完了,叫预处理。

所以link的时候,会出现重复定义。

读书人网 >C语言

热点推荐