Switch case glitch hitch pitch? Compilation error - but not on Arduino

The code below compiles fine on Arduino (I don’t know how to make them show up here, but there are in fact MULTIPLE spaces between “switch” and the opening bracket of the switch variable). But, on Sparkcore web interface, unless you reduce the spaces to just one, you get a compiler error.

Yep, pretty stoopid to have junk spaces there, but it could happen (as in my case) inadvertently and I would have thought that (like the Arduino compiler) it shouldn’t matter? Problem is, the Spark compiler error message mentions bad characters “before switch”, so I wasted quite a long time looking at the code preceding the switch-case.

Is this a repeatable problem, or something specific to my set-up?

Thanks as ever
Best
Alan T,.

=======

    char inBuff[20];
void setup()
{
}

void loop()
{
  switch      (inBuff[0])
  {
  case 'a':
    // Do something if 1st char was 'a'
    break;

  default:
    // Do something else if it wasn't.  
    break;
  }
}
1 Like

Yes, it looks like multiple spaces are converted to (or seen as) a tab, which will generate the same error...

Patient: "Doc, it hurts when I move my arm"
Doctor: "Well... don't do that"

I imagine the Arduino IDE probably strips out unnecessary white space while the Spark compiler does not. Just something to keep in mind. Perhaps @Dave has a suggestion?

Hey All,

Hmm, as far as I know I’m not removing / converting any whitespace, if I had to point to a culprit, I would suspect the function definition matching is getting confused. You can always try compiling with #pragma SPARK_NO_PREPROCESSOR to turn all that off. :slight_smile:

I’m hoping we’ll get a chance to revisit the compiler preprocessor later this year and make it much smarter.

Thanks,
David

3 Likes