expected unqualified-id before '{'

When I compile my code I get an error on my void loop, I get "expected ungualified-id before'{'."

void loop()
{
if ( millis() - Previous1 >= Interval1)
{
Previous1 = millis();
ParseOpticsData(); // Parse data from Roborealm
PrintData(); // Print out data for analysis
if(Count != Repeats && var[0] > 0)
{
PanTilt(); // Get angles to set for pan/tilt servos
Wheels(); // Get pwms to set for wheels
}
}
if(Count == Repeats)
{
if(var[0] == 0){
if(millis() - Previous2 >= Interval2){
Previous2 = millis();
ResetPanTilt(); // Reset pan/tilt servos
UpdatePanTilt(); // Update current pan/tilt angle
}
}
if(millis() - Previous3 >= Interval3){
Previous3 = millis();
StopWheels(); // Bring wheels to a stop
UpdateWheels(); // Update current wheel pwms
}
}
else{
if(millis() - Previous4 >= Interval4){
Previous4 = millis();
UpdatePanTilt(); // Update current pan/tilt angle
}
if(millis() - Previous5 >= Interval5){
Previous5 = millis();
UpdateWheels(); // Update current wheel pwms
}
}
}

What is before void loop()?

I have a long code but I can post it if you'd like.

This is what I have before the void loop

void setup(){
// SERIAL PORTS\
  Serial.begin(115200);               // Open serial port\
  Serial1.begin(115200);              // Open serial port\

// PAN/TILT\
  PanServo.attach(PanPin);            // Attach panServo to pin\
  PanServo.write(PanAngle);           // Initialize panServo to 90\


// WHEELS\
  pinMode(LWheel,OUTPUT);             // Sets the pin as output\
  pinMode(RWheel,OUTPUT);             // Sets the pin as output\
  analogWrite(LWheel,LWheelPWM);      // Initialize LeftWheel to PWM 128\
  analogWrite(RWheel,RWheelPWM);      // Initialize RightWheel to PWM 128\
}

Try getting rid of the \ at the end of the lines.


Rob

Thank you Graynomad!! Can not believe that was it.

Bump

"Bump" what? OP's problem was solved. If you have a problem, define what the problem is, what the error message is, and post some code.

Or quit bumping.

Bump

I smell spam.

Not trying to "bump" this again, but in all seriousness, that is technically okay syntax. Is that a known compiler issue? Using Microsoft Visual Studio, it works fine. It's just an odd error that pops up.

It is not "OK syntax" - the backslash is a line-continuation, so

analogWrite(RWheel,RWheelPWM);      // Initialize RightWheel to PWM 128\
}

is seen by the compiler as

analogWrite(RWheel,RWheelPWM);      // Initialize RightWheel to PWM 128 }

so the compiler doesn't see the closing brace.

Using Microsoft Visual Studio, it works fine.

That's no recommendation at all.

Hmm, Okay. I mainly use Visual Studio for C++ and it works in there. That's why I was wondering.

I mainly use Visual Studio for C++ and it works in there

That is quite hard to understand - the backslash operator is used a lot in long preprocessor macros, and if it doesn't work here, then there must be some big question marks over the compiler.
What happens if you compile this?

int main (int argc, char** argv)
{
  // This comment should cause the compilation to fail \
}

I couldn't resist...

post some code. Or quit bumping.

... that's what she said! :slight_smile:

Ah, I see. I was doing it with something that had a couple of lines of code which worked (compiled that is).

So:

int main(){
int a = 0;
//this is a comment \ 
int b = 1;
}

vs.

int main(){
int a = 0;
//this is a comment \ 
}

The top one works, but does not assign 1 to a b variable, the bottom one breaks. I see now. I feel dumb :disappointed_relieved:, but then again I haven't ever tried that.