What is the function of ifdef in the C language?
In the C language, #ifdef is a conditional compilation directive used to check if a macro has been defined. Its purpose is to selectively include or exclude certain code segments based on the results of the conditional compilation.
The format for using #ifdef is as follows:
#ifdef 宏名
// 如果宏被定义,则执行此处代码
#else
// 如果宏未定义,则执行此处代码
#endif
When a macro is defined, the code after #ifdef will be compiled; when the macro is not defined, the code after #ifdef will be skipped. By using conditional compilation directives, it is possible to selectively compile different code according to the needs, in order to achieve adaptation to different platforms, configurations, or requirements.