C语言头文件的一些规则:
(1)每个头文件的首部应该加上描述信息
/**************************************************************
function:
description:
arguments:
return value:
calls:
globals:
****************************************************************/(2)整个文件的其余代码应该包含在Guard Define内
#ifndef __MAIN_H__
#define __MAIN_H__
#endif(3)给C++引用的头文件还应该有extern "C"标示
#ifdef __cplusplus
extern "C"
{
#endif
//codes
#ifdef __cplusplus
}
#endif(4)将数据结构隐藏在头文件中
typedef struct file_opt file_opt;(5)在函数声明时区分函数的用途
#define CAM_API extern
CAM_API unsigned char *get_image(int fd); //被其它函数调用
void show_image(char *img); //被用户调用(6)在定义宏时,使用括号
#define MAX(a,b) ( (a)>(b) ? (a) : (b) )

531

被折叠的 条评论
为什么被折叠?



