环境:Vmware Workstation;CentOS-6.4-x86_64
说明:
通过c++编译器预定义的一个宏“__cplusplus”,实现C和C++通用的头文件。
头文件样式如下:
#ifndef __MYHEADER_H__ // 如果没有定义,就执行下面的语句
#define __MYHEADER_H__ // 定义宏__MYHEADER_H__
#ifdef __cplusplus // 如果定义了宏__cplusplus,就执行下面的语句
extern "C"{
#endif
#include <stdio.h>
#include <stdlib.h>
// 求两个参数的最大值
int add(int a, int b);
// 求两个参数的和
int max(int a, int b);
#ifdef __cplusplus
}
#endif
#endif
PS:根据传智播客视频学习整理得出。