【发布时间】:2011-01-15 11:27:10
【问题描述】:
假设我像这样在“struct.h”中定义一个结构
struct box {
int value;
}
我在另一个文件中使用该结构说“math.c”
#include "struct.h"
struct box *sum(struct box *a1, struct box *a2) {
struct box *a3 = malloc(sizeof (struct box));
a3->value = a1->value + a2->value;
return a3;
}
“math.h”是否也需要包含“struct.h”?
#include "struct.h"
struct box *sum(struct box *a1, struct box *a2);
如果 struct box 被替换为 bool,我需要在头文件和 c 文件中包含 stdbool.h 吗?似乎编译器想要这个。
什么时候应该在标头而不是 .c 中包含文件?也想知道我的例子是否有什么不寻常的地方。
谢谢!
【问题讨论】:
标签: c