22_条件编译使用分析
1、条件编译的本质
条件编译类似于if…else…,但是其发生在预处理阶段
宏定义可以通过命令行进行:
####2、条件编译的使用举例
示例1:防止头文件重复包含
#ifndef _HEADER_FILE_H_
#define _HEADER_FILE_H_
//source code
#endif
// test.h
#ifndef _TEST_H_
#define _TEST_H_
#include "global.h"
const char* NAME = "test.h";
char* hello_world(){
return "Hello world!\n";}
#endif
// global.h
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
int global = 10;
#endif
示例2:产品线区分及调试代码应用
//product.h
#define DEBUG 1
#define HIGH 1
//product.c
#include <stdio.