Strange error... and I don't know if it's my own...

I was trying to upload my sketch involving the servo library when I got this error message:

[color=red]In file included from Bot.cpp:8:
C:\[deleted because this stuff reveals personal info]\Arduino\hardware\arduino\cores\arduino/WProgram.h:18: error: expected ',' or '...' before numeric constant[/color]

The code at line 8 is:

Servo lMotor

I looked at WProgram.h and on line 18 there is:

uint16_t makeWord(byte h, byte l);

Anyone know what's going on?

Because Arduino puts some declarations at the top of your compile, line numbers displayed with error messages are usually one higher than the line number in your code. If you provide all of the code perhaps someone can determine how to get it compiled.

Are you using Arduino 1.0? Wprogram.h was replaced with Arduino.h in 1.0.

johnwasser:
Because Arduino puts some declarations at the top of your compile, line numbers displayed with error messages are usually one higher than the line number in your code. If you provide all of the code perhaps someone can determine how to get it compiled.

Here:

#include <Servo.h>

#define lCal 0
#define rCal 0
#define l 10
#define r 9

Servo lMotor;
Servo rMotor;

void setup() {
  lMotor.attach(l);
  rMotor.attach(r);
  Serial.begin(9600);
}

void loop() {
  lMotor.write(180);
  rMotor.write(180);
}

Are you using Arduino 1.0? Wprogram.h was replaced with Arduino.h in 1.0.

I was too lazy to update... (yep) I just did because you said that, and now the error talks about Arduino.h and line 195.

EDIT: I deleted the #defines for the pin numbers and replaced it with actual numbers and it works fine.
...I'm still curious to know what's going on. :confused:

You are running into an obscure error caused by the way the IDE converts the sketch into a .cpp file.
A workaround is to put this line of code at the very front of your sketch:

char junk;

Pete
P.S. This ought to be a "sticky" subject but the problem is that it causes all sorts of weird errors which don't seem to be related to the real cause.

The problem is this line:

#define l 10

When that gets in before:

uint16_t makeWord(byte h, byte l);

that line gets interpreted as:

uint16_t makeWord(byte h, byte 10);  // Syntax problem caused by text substitution.

The fix, and generally better programming practice, is to use a constant integer:

const int l = 10;

The fix, and generally better programming practice, is to use a constant integer:

Another solution is to not ignore the convention that #define names should be all upper case. L and l are not the same, so the problem would not have occurred.