首页 > 其他 > 详细

【C】head file (.h)

时间:2019-02-12 22:39:25      阅读:217      评论:0      收藏:0      [点我收藏+]

几个要点:

  1. 在源文件中使用头文件,等于将头文件的内容原封不动的复制过来;
  2. 对于源文件“abc.c”,一般会设置一个“abc.h”,将程序中用到的头文件全部集中到“abc.h”中;
  3. 函数、全局变量的声明(declaration)一般都会放在头文件,方便其他文件调用
  4. 在一个源文件中,同一个头文件不能被多次调用,故需要保护(include guard)
  5. 可以导入其他文件夹中的头文件

具体例子:

  include guard:

/*Swmm5Extend.h*/

//if this head file is called before, nothing will be reached
#ifndef SWMM5EXTEND_H 
//this can be everything, but SWMM5EXTEND_H is clear
#define SWMM5EXTEND_H

/*
other head files
*/

#endif // !SWMM5EXTEND_H

  导入其他文件夹内的头文件:

/*in the subdirectory*/
#include "/subdirectory/structure.h"

/*in another directory*/
#include "../anotherdirectory/structure.h"

//Linke:
//https://stackoverflow.com/questions/7581408/including-a-header-file-from-another-directory

 

【C】head file (.h)

原文:https://www.cnblogs.com/kimilin/p/10367132.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!