The #error command is one of the preprocessing commands of the C/C++ language. When the preprocessor preprocesses to the #error command, it will stop compiling and output a user-defined error message.
The following code outputs the number 1000. If #error is added, the build will not pass, and the error message is as follows;
This may be useful in larger projects;
The following is said to be an example in the freertos source code,
#ifndef configEXPECTED_IDLE_TIME_BEFORE_SLEEP
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2
#endif
#if configEXPECTED_IDLE_TIME_BEFORE_SLEEP < 2
#error configEXPECTED_IDLE_TIME_BEFORE_SLEEP must not be less than 2
#endif
如果configEXPECTED_IDLE_TIME_BEFORE_SLEEP 定义的小于2,则编译出错;