写好C语言的头文件

来源:互联网 发布:国家一级蜥蜴知多少 编辑:程序博客网 时间:2024/05/01 14:50

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) )
原创粉丝点击