假设file1.h
里面有一些file.c
需要使用的头文件以及:
//file1.h 提供了file1.c的函数和struct定义以及常量等接口,供外部文件调用
#ifndef __FILE1_H_
#define __FILE1_H_
#inlucde <stdio.h>
#include "file2.h"
#include "file3.h"
#endif
而file1.c
里面也包含了一些头文件:
#include "file1.h" //自包含
#include "file4.h"
那么问题来了:哪些头文件该包含在file1.h
中,哪些头文件该包含在file1.c
中?
大家有什么头文件包含的规范或者经验吗?谢谢啦!
如果你发现include了file1.h后,file2.h是必须include的(否则compile error),那#include "file2.h"写在file1.h里。如果file2.h是可选的,就写在要用的c/cpp文件里。