使用MDK调试程序的时候,出现了以下错误:
#268: declaration may not appear after executable statement in block
错误原因
Keil C compilers are based on ANSI C C90 standard, but are expanded with added language extensions, practical concessions to the architectural peculiarities of the microcontrollers, and other features that meet the needs of embedded systems programmers.
In C90, all variable declarations must happen before any executable statements in a function or other code block. The compiler error message mentions the line number of the offending line of code.
简单讲就是C90的原因
解决方法
C99 enables you to mix declarations and statements within compound statements, like in C++. Turn on C99 mode in the Keil IDE under Project → Options for Target → C/C++ tab, and check C99 Mode. Read more about the –c99 compiler switch here.
即,将MDK里的C语言标准改为C99