Skip to content

编译预处理 ​

(一)定义符号常量 ​

定义常量 ​

c
#define 标识符 常量表达式

例如:

c
#define DELAY_TIME 200

系统预定义常量 ​

系统已经定义好了以下常量:

c
#define NULL    0
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define EOF     -1
#define TRUE    -1
#define FALSE   0

这些常量不需要在LavaX程序中定义了。

取消定义 ​

c
#undef 标识符

(二)文件包含 ​

c
#include "文件名"

例如:

c
#include "time.h"

(三)条件编译 ​

条件编译命令有以下三种形式:

1. 如果定义了标识符 ​

c
#ifdef 标识符
    程序段1
#else
    程序段2
#endif

2. 如果未定义标识符 ​

c
#ifndef 标识符
    程序段1
#else
    程序段2
#endif

3. 如果常量表达式为真 ​

c
#if 常量表达式
    程序段1
#else
    程序段2
#endif