#if defined ||
时间: 2023-09-05 09:13:44 浏览: 143
【C/C++】#ifndef,#define用法
`#if defined` is a preprocessor directive in C/C++, used to check if a macro has been defined or not. If the macro has been defined, it evaluates to true, otherwise false. The syntax is as follows:
```
#if defined MACRO_NAME
// code to be executed if MACRO_NAME is defined
#else
// code to be executed if MACRO_NAME is not defined
#endif
```
For example:
```
#define DEBUG_MODE
#if defined DEBUG_MODE
printf("Debug mode is enabled\n");
#else
printf("Debug mode is disabled\n");
#endif
```
In this example, since `DEBUG_MODE` has been defined, the first block of code will be executed, printing "Debug mode is enabled" to the console.
阅读全文