c – Why doesn’t this compile in C18? – Education Career Blog

I’m trying to compile the following code using the MPLAB C18 v3.36 compiler.

Compiler returns a syntax error on ‘char rij;’.
But when i put char rij; a line earlier (before TRISA = …), it compiles …

void setup(void)
{
 TRISD = 0b00000000;
 TRISA = 0b00000000;
 char rij;
 for (rij = 0; rij<ROWS; rij++)
 {
 red_byte_arrayrij=0;
 green_byte_arrayrij=0;
 blue_byte_arrayrij=0;
 }    
}

,

Although I’m not familiar with this compiler I would guess that it follows C89 semantics which forbid mixing declarations with statements. Therefore you can only declare variables on the beginning of the block.

Leave a Comment