【发布时间】:2017-04-17 12:04:35
【问题描述】:
如何在测试头文件中的方法的源文件中调用在头文件中实现方法的 c 源文件。我正在使用 Devc++ IDE 例如
sum.h
#ifndef SUM_H_
#define SUM_H_
int add(int a, int b);
#endif
sum.c
#include"sum.h"
int add(int a, int b){
return a+b;
}
sumtest.c
#include "sum.h"
int main(){
int a = 10;
int b = 10;
printf("the sum of a and b is : %d", add(a, b));
return 0;
}
请代码仅用于说明。 所以在上面的代码中,sumtest.c 是如何知道 add 的实现的,即使 sumtest.c 中没有明确包含“#include sum.c”。
【问题讨论】:
-
编译器在构建
sumtest.c源文件时,会从头文件中看到声明(因为包含在内),知道有一个函数叫做@987654324 @某处。 -
你为什么回滚编辑?有没有cmets?
-
@Sourav Ghosh 这是一个错误,不是故意感谢您的编辑。
标签: c compilation header-files