keil编译stm32程序出现declaration may not appear after executable statement in block 错误 解决办法...

int32_t Data(uint8_t * data, uint32_t len)
{
int32_t ret = 0;
uint8_t tx_buf[MAX_PACKAGE_LEN];

if(NULL == data)
{
printf("[Error] Data Error \n");
return (-1);
}
uint8_t *pTxBuf = tx_buf;
uint16_t data_len = 6+len;

/*****省略程序******/

 

出现下面错误 error:  #268: declaration may not appear after executable statement in block

 error: #268: declaration may not appear after executable statement in block
uint8_t *pTxBuf = tx_buf;
error: #268: declaration may not appear after executable statement in block
uint16_t data_len = 6+len;

解决办法:变量声明不允许出现在语句之后.这种在语句之后声明变量的方式,c++允许,现在的很多c编译器也允许。
最早的c是不许这么写的,要求所有的局部变量必须在函数开头声明。
把uint8_t *pTxBuf = tx_buf;uint16_t data_len = 6+len;这两行移到函数最开头

转载于:https://www.cnblogs.com/yekongdexingxing/p/6605190.html

你可能感兴趣的:(keil编译stm32程序出现declaration may not appear after executable statement in block 错误 解决办法...)