c语言 宏定义 去除宏定义
To check whether a Macro is defined or not in C language – we use #ifdef preprocessor directive, it is used to check Macros only.
要检查是否用C语言定义了宏 -我们使用#ifdef预处理程序指令,它仅用于检查宏。
Syntax:
句法:
#ifdef MACRO_NAME
//body
#endif
If MACRO_NAME is defined, then the compiler will compile //body (a set of statements written within the #ifdef ... #endif block).
如果定义了MACRO_NAME ,则编译器将编译// body (在#ifdef ... #endif块中编写的一组语句)。
Example:
例:
#include <stdio.h>
#define NUM 100
int main()
{
//checking a defined Macro
#ifdef NUM
printf("Macro NUM is defined, and its value is %d\n",NUM);
#else
printf("Macro NUM is not defined\n");
#endif
//checking an undefined Macro
#ifdef MAX
printf("Macro MAX is defined, and its value is %d\n",MAX);
#else
printf("Macro MAX is not defined\n");
#endif
return 0;
}
Output
输出量
Macro NUM is defined, and its value is 100Macro MAX is not defined
翻译自: https://www.includehelp.com/c-programs/check-whether-a-macro-is-defined-or-not-in-c.aspx
c语言 宏定义 去除宏定义