queezythegreat / arduino-cmake

Arduino CMake Build system
645 stars 216 forks source link

Syntax error with 'else if' #164

Open galou opened 8 years ago

galou commented 8 years ago

I may have found a bug probably during preprocessing of an ino file by arduino-cmake.

Excerpt (I cannot show the whole file):

void loop()
{
    if (true)
    {
    }
    else if (true)
    {
    }
}

Produces an error:

error: expected unqualified-id before ‘else’
      else if (true)     ;

The generated cpp file is (excerpt)

 void setup() ;
 void setup() ;
 void loop() ;
 void loop() ;
     else if (true)     ;
     else if (true)     ;

If I change the else if with if, the file compiles.

However, I could not reproduce with the following with a simple sketch file which works

void setup() {}
void loop()
{
      if (true)
    {
    }
    else if (true)
    {
    }
}
oldmud0 commented 7 years ago

There is a syntax error in the inner body of your if block. Make sure that you end with the same number of braces that you started with. Please be sure to brush up on C++ while you are on it.