C语言预处理指令#error
程序员文章站
2024-02-22 15:34:16
...
在FreeRTOS的FreeRTOS.h文件中看到一句代码
#ifndef configMINIMAL_STACK_SIZE
#error Missing definition: configMINIMAL_STACK_SIZE must be defined in FreeRTOSConfig.h. configMINIMAL_STACK_SIZE defines the size (in words) of the stack allocated to the idle task. Refer to the demo project provided for your port for a suitable value.
#endif
然后我把FreeRTOSConfig.h中的宏configMINIMAL_STACK_SIZE注释掉,然后编译,报错如下:
..\FreeRTOS\inc\FreeRTOS.h(82): error: #35: #error directive: Missing definition: configMINIMAL_STACK_SIZE must be defined in FreeRTOSConfig.h. configMINIMAL_STACK_SIZE defines the size (in words) of the stack allocated to the idle task. Refer to the demo project provided for your port for a suitable value.
可以看到,#error在这里用来判断是否定义了某个宏,如果没有定义就产生一个编译错误,有利于后期排错。除此之外,也可以用来判断某个宏的值是否符合要求。