There appears to be no category for the web IDE so General it is.
I ran across a strange occurrence today using a simple if, else if routine. I have narrowed it down to the following. I have removed any variable names and just used the number 1 for clarity. Using a boolean or integer for the test results in the same error.
int a;
void setup() {
}
void loop() {
if (1) {
a++;
}
else if (1) {
a--;
}
}
This gives me the following error.
"if_else_test.cpp:5:1: error: expected unqualified-id before 'else’
else if (1);
^
If I make a simple change to the else if test like this
int a;
void setup() {
}
void loop() {
if (1) {
a++;
}
else if (!1) {
a--;
}
}
I get the coveted “Code verified! Great work.”
Is this something I’m not understanding or is this an IDE problem?
I guess that settles it for me. Dump the preprocessor.
Other than forcing programming to adhere to a more structured format and including application.h, which is good anyways, is there any disadvantage to not using the preprocessor?
When you are not using the preprocessor, you are not writing in “Wiring,” the simplified version of C that Arduino uses. You are instead writing in straight C (or C++).
That means you need to provide function prototypes and any other forward references just like you normally do in C.
Since I have never played with or in the Arduino ecosystem and just discovered that all of my programs actually compile with #pragma SPARK_NO_PREPROCESSOR added it must mean that I am actually learning something about C/C++ programming.
For me that’s an accomplishment! Now if I could only stop forgetting those darn semicolons.