I'm new (or newly returned) to Keil C51 -- pardon if this is a well understood issue:
In Keil C51 (v 9.6.0) it appears that variable declarations must be the first thing in a block. I'm accustomed to other C compilers where this requirement was dropped long ago. Specifically, this code fails to compile in C51 with the error:
*** ERROR C141 IN LINE 190 OF C:.../foo.c: syntax error near 'int', expected '__asm'
int foo(int x) { if (x == 0) { return 0; } int i = x+1; return i;}
But this code compiles without error:
int foo(int x) { int i; if (x == 0) { return 0; } i = x+1; return i;}
Since I'm porting a large body of code that uses the more "modern" syntax, is there a compiler flag I can set that will cause C51 to permit this?
I found the answer here:
Keil C51 Compiler C99 compliant? - Silicon Labs (silabs.com)
Specifically, C51 is C90 compliant, not C99 compliant. (Sherman, set the Wayback machine for 1990!) I'll deal with it.