多重嵌套宏定义带来的错误fatal error: parser recursion limit reached,program too complex
宏定义又称为宏代换、宏替换。
格式: #define 标识符 字符串
注意:若这个字符串是数字,最好用小括号套住它,否则,在进行宏替换时,可能会产生错误。在使用"多重嵌套宏定义"一定要小心,否则可能会导致意想不到的错误,这种错误很隐秘,很难被发现。
问题1:
#define A0 0
#define A1 (A0+1)
#define A2 (A1+1)
.
.
.#define A500 (A498+1)
#define A500 (A499+1)
A500=(((A0+1)+1)+......+1)
注意:
每个小括号会占用一个栈空间,中间结果太多了,程序会先计算A1,再计算A2,这些值会占用栈空间,导致空间满了,叫栈溢出。
多重嵌套宏定义,会产生fatal error: parser recursion limit reached,program too complex(致命错误:解析器递归极限达到,程序太复杂),编译器没有警告,也没有错误,只是才错误行提示错误,非常隐藏,有的干脆不报警。
解决方法1:
为了防止出现多重嵌套宏定义,最好采用基地址、偏移地址和结束地址进行宏定义:
#define A_BASE_ADDRESS (( uint32_t )0) //网页名:http://www.hezhong-cloud.com/”
#define A_Buffer_Size (( uint32_t )35)
#define A_END_ADDRESS ( uint32_t )( WEB_PAGE_NAME_ADDRESS + A_Buffer_Size - 1 ) //设备ID结束地址为34
#define B_BASE_ADDRESS ( uint32_t )(DSP_WebPageAddressBuffer_Size) //设备ID开始地址为35
#define B_Buffer_Size (( uint32_t )17)
#define B_ADDRESS_SIZE (uint32_t)( ( (uint32_t)B_Buffer_Size ) * ( (uint32_t)24 ) ) //最大偏移地址为408
#define B_END_ADDRESS ( uint32_t )( B_BASE_ADDRESS + B_ADDRESS_SIZE - 1 ) //设备ID结束地址为442
#define B_ADDRESS1 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 0) ) //保存设备ID;
#define B_ADDRESS2 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 1) ) //保存设备ID;
#define B_ADDRESS3 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 2) ) //保存设备ID;
#define B_ADDRESS4 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 3) ) //保存设备ID;
#define B_ADDRESS5 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 4) ) //保存设备ID;
#define B_ADDRESS6 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 5) ) //保存设备ID;
#define B_ADDRESS7 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 6) ) //保存设备ID;
#define B_ADDRESS8 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 7) ) //保存设备ID;
#define B_ADDRESS9 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 8) ) //保存设备ID;
#define B_ADDRESS10 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 9) ) //保存设备ID;
#define B_ADDRESS11 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 10) ) //保存设备ID;
#define B_ADDRESS12 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 11) ) //保存设备ID;
#define B_ADDRESS13 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 12) ) //保存设备ID;
#define B_ADDRESS14 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 13) ) //保存设备ID;
#define B_ADDRESS15 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 14) ) //保存设备ID;
#define B_ADDRESS16 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 15) ) //保存设备ID;
#define B_ADDRESS17 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 16) ) //保存设备ID;
#define B_ADDRESS18 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 17) ) //保存设备ID;
#define B_ADDRESS19 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 18) ) //保存设备ID;
#define B_ADDRESS20 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 19) ) //保存设备ID;
#define B_ADDRESS21 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 20) ) //保存设备ID;
#define B_ADDRESS22 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 21) ) //保存设备ID;
#define B_ADDRESS23 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 22) ) //保存设备ID;
#define B_ADDRESS24 ( B_BASE_ADDRESS + (uint32_t)( (uint32_t)B_Buffer_Size * 23) ) //保存设备ID;