#if, #ifdef, #ifndef, #else, #elif, #endif These commands give simple logic control to the compiler. As a file is being compiled, you can use these commands to cause certain lines of code to be included or not included. If the value of expression is true, then the code that immediately follows the command will be compiled. If the macro has been defined by a #define statement, then the code immediately following the command will be compiled. If the macro has not been defined by a #define statement, then the code immediately following the command will be compiled. A few side notes: The command #elif is simply a horribly truncated way to say "elseif" and works like you think it would. You can also throw in a "defined" or "!defined" after an #if to get added functionality. Example code: Here's an example of all these: You might notice how that second example could make debugging a lot easier than inserting and removing a million "cout"s in your code. |
C语言-函数-#if, #ifdef, #ifndef, #else, #elif, #endif
最新推荐文章于 2023-11-16 15:56:47 发布