This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Keil C51: variable declarations must be first in a block?

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?

Parents Reply Children
No data