标题: error: declaration may not appear after executable statement in block [打印本页]

作者: niujia    时间: 2015-7-17 16:51
标题: error: declaration may not appear after executable statement in block


这个问题是在编译STM32的程序时遇到的,这个错误的原因是对于变量的声明不能放在可执行语句后面,必须在主函数开头声明变量。在程序中声明一个变量时,需要在可执行语句之前声明,否则会出现以上错误。

例:

vu16 KeyPortState=0;
SystemInit();   

KeyScanState_Typedef KeyScanState=KeyScanState_0; //KeyScanState_Typedef 为作者自定义的结构体
GPIO_Configuration();     

以上编译会出项错误,原因是KeyScanState_Typedef KeyScanState=KeyScanState_0; 出现在SystemInit();之后。

正确的函数语句段是:

vu16 KeyPortState=0;

KeyScanState_Typedef KeyScanState=KeyScanState_0;
SystemInit();
GPIO_Configuration();







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1