#define, #undef
举例:
/* 定义常量 */
#define ARRAY_SIZE (512)
/* 定义函数宏 */
#define min(a,b) ((a)<(b)? (a):(b))
/* 头文件只包含一次 */
#ifndef MYHEADER_H
#define MYHEADER_H
/* The body of the header file */
#endif /* MYHEADER_H */
/* 取消宏 */
#ifdef MYCOUNT
#undef MYCOUNT
#error ,#warning
说明:#error产生错误消息于处理器终止。#warninig产生一条警告消息,预处理不停止。
举例:
#ifndef __unix__
#error "This section will only work on UNIX systems"
#endif
#warning "this is a warninig"
#if, #elif, #else, #endif
举例:
#if defined(MINXP)
#endif
#if !defined(MINXP)
#endif
#if !(LIMXP > 12)
#endif
#ifdef MINXP
#endif
#ifndef MINXP
#endif
#if MINTXT <= 5
#define MINTLOG 11
#elif MINTXT == 6
#define MINTLOG 12
#elif MINTXT == 7
#define MINTLOG 13
#else
#define MINTLOG 14
#endif
#,##,__VA_ARGS__
/* #宏参数字符串化 */
#define SQRT(ARGTERM) printf("the term " #ARGTERM " is a string\n")
SQRT(far); /* printf("the term far is a string\n") */
/* ## 两个字符串组合成一个 */
#define MONCK(a) x##a
MONCK(far); /* xfar */
/* ##__VA_ARGS__ <span style="color: rgb(255, 102, 0); font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">宏前面加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错</span>*/
#define errout(a,b,...) \
fprintf(stderr,"File %s Line %d\n",a,b); \
fprintf(stderr,##__VA_ARGS__)