error: declaration may not appear after executable statement in block

来源:互联网 发布:mysql.sock 不存在 编辑:程序博客网 时间:2024/05/17 21:50

这个问题是在编译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();

0 0
原创粉丝点击