-1

我在制作简单的 cosole C 应用程序时已将所有文件包含在代码块中,但是当我定义宏时出现此错误。我猜链接器无法链接项目中的所有文件。我在项目 test1.c 中包含两个文件,文件中的 test1.h 代码如下所示..

文件 :::::test1.c

#include<stdio.h>
void m();
#include "test1.h"
#define DS==1

int main(){




return 0;
}

文件::::test1.h

#ifndef TEST1_H_INCLUDED
#define TEST1_H_INCLUDED

#if DS ==1
void m(){

printf("hello DS==1");

}

#eliif DS==2
void main(){
printf("hello DS==2");

}
#endif


#endif // TEST1_H_INCLUDED

错误在于

**> E:\Documents\Myprojects\My C PRoj\Te\test1.c||在函数'main'中:|

E:\Documents\Myprojects\My C PRoj\Te\test1.c|8|warning: implicit declaration of function 'm'|
obj\Debug\test1.o||In function `main':|
E:\Documents\Myprojects\My C PRoj\Te\test1.c|8|undefined reference to `m'|
||=== Build finished: 1 errors, 1 warnings ===|**

如果我删除条件宏,只需使用以下代码进行编译:

文件:::::test1.c

#include<stdio.h>
#include "test1.h"


int main(){

m();


return 0;
}

文件:::::test1.h

#ifndef TEST1_H_INCLUDED
#define TEST1_H_INCLUDED

void m(){

printf("uncoditional macro");

}

#endif // TEST1_H_INCLUDED

一切正常。这是什么原因?

4

1 回答 1

3

该表达式++a+( a+b)是未定义的行为,因为在更新和使用之间缺少序列点。a输出可以是任何东西。

于 2013-07-01T13:30:39.953 回答