[Solved] Really strange compilation error

Can somebody explain to me why this code:

bool turnedLeft = false;
bool turnedRight = false;
unsigned long lastChange = 0;

void setup() { }

void loop() 
{
    if(turnedLeft || turnedRight) 
    {
        lastChange = millis();
    
        if(turnedLeft) { }
        else if(turnedRight) { }
    }
}

Results in the following error ?

testerror.cpp:5:1: error: expected unqualified-id before 'else'
else if(turnedRight);

Maybe its just too late in the day, but I can’t see why this should happen ^^

Also is there a way to see what testerror.cpp contains ? I guess its precompiled from “testerror.ino”.

SOLUTION: https://community.spark.io/t/really-strange-compilation-error/10126/2

1 Like

The Spark Preprocessor is at it again! By disabling the preprocessor (and remembering to include “application.h”) I was able to get your exact code working

#pragma SPARK_NO_PREPROCESSOR
#include "application.h"

bool turnedLeft = false;
bool turnedRight = false;
unsigned long lastChange = 0;

void setup() { }

void loop() 
{
    if(turnedLeft || turnedRight) 
    {
        lastChange = millis();

        if(turnedLeft) { }
        else if(turnedRight) { }
    }
}
1 Like

That’s really strange indeed. I once had a similar error but I cannot remember how I fixed it

Edit: Nvm this haha :wink:

Ahh, thought so :smile:
I found that

if(turnedLeft) { }
else if(turnedRight == true)

also works.