Web IDE compiling - comments causing issues

Is anyone else experiencing issues with compiling. I have code which was compiling fine and now won’t. I have been working through it and it seems comments are causing problems for the compiler. So I don’t bore you with unnecessary code see the simple examples below. This first one compiles fine

void setup() {
    Particle.function("test", test);
}
void loop() {
}
int test(String command) {
    return 1;
}

But if you add a comment like below - I get a “‘test’ was not declared in this scope” error

//Comments are causing issues
void setup() {
    Particle.function("test", test);
}
void loop() {
}
int test(String command) {
    return 1;
}

That is a known issue of the Particle Wiring preprocessor.
You can try to add another blank line before/after the comment or just ditch the preprocessor completely via

#pragma SPARK_NO_PREPROCESSOR
#include "Particle.h"

// add function prototypes/forward declarations where needed
1 Like

Unfortunately I still am having issues. If I add in lines before and after as per below (there is a blank line on line 1

//ssss

void setup() {
    Particle.function("test", test);
}
void loop() {
}
int test(String command) {
    return 1;
}

If I add in the code you recommended so the files is

#pragma SPARK_NO_PREPROCESSOR
#include "Particle.h"

//ssss


void setup() {
    Particle.function("test", test);
}
void loop() {
}
int test(String command) {
    return 1;
}

I get the same error

junk.cpp: In function ‘void setup()’:
junk.cpp:8:31: error: ‘test’ was not declared in this scope
make[1]: *** […/build/target/user/platform-6junk.o] Error 1
make: *** [user] Error 2

It has only come about today on code which was working before. Can you get the examples above to compile?

Hi @stofmike

Once you have the no preprocessor pragma in place, you must abide by normal C/C++ rules, including the order of functions or using function prototypes.

In this case, you need to move the function test above the function setup() so it will be defined before you try to use it in the Particle.function call.

1 Like

What @bko just said there is what I meant with the comment

in that snipped :wink:

1 Like