1

I have an extrange Problem... I have written this short code:

////////////// BOARD SETTINGS \\\\\\\\\\\\\\
#define BAUD_RATE 9600

// Board type selection
// Uncomment the wanted
//#define WAND 0
//#define GUN 0
#define RIFLE 0


////////////// WAND SETTINGS \\\\\\\\\\\\\\
#ifdef WAND
//#define USE_CHARGER 0

#endif

////////////// GUN SETTINGS \\\\\\\\\\\\\\
#if GUN
//#define USE_CHARGER 0

#endif

////////////// RIFLE SETTINGS \\\\\\\\\\\\\\
#ifdef RIFLE
  #define USE_CHARGER 0

#endif

It's in a file called Settings.h, that I use in the main code:

#include "Settings.h"

void setup(){
  Serial.begin(BAUD_RATE);
  #ifdef WAND
    Serial.println("Initializing Wand...");
  #endif
  #ifdef GUN
    Serial.println("Initializing Gun...");
  #endif
  #ifdef RIFLE
    Serial.println("Initializing Rifle...");
  #endif
}

void loop(){
  #ifdef WAND

  #endif
  #ifdef GUN

  #endif
  #ifdef RIFLE

  #endif
}

But for an extrange reason, it gives me this error: error: #endif without #if Full error is:

In file included from D:\MEGA\Winsoft\Projects\Hardware\MWands\Arduino_5\Arduino_5.ino:1:0:

Settings.h:15: error: #endif without #if

 #endif

  ^

Settings.h:21: error: #endif without #if

 #endif

  ^

Settings.h:27: error: #endif without #if

 #endif

  ^

exit status 1
#endif without #if

Any idea in where am I wrong?

And taking advantage that I'm asking, is necessary the 0 after #define RIFLE 0, next to each definition?

4
  • The way you are using it, no you dont' have to add the 0 #define XYZ is enough. #ifdef XYZ will work for this case.
    – Mazaryk
    May 3 '17 at 16:25
  • Also, you have declared #if GUN which you probably meant #ifdef GUN.
    – Mazaryk
    May 3 '17 at 16:25
  • Using #ifdef and ending with #endif still showing me that error May 3 '17 at 16:27
  • I didn't say it would fix the error, I was just answering your second question "is it necessary to have the 0..."
    – Mazaryk
    May 3 '17 at 16:28
1

It looks like your comment style is causing the problem.

Remove the ////////////// BOARD SETTINGS \\\\\\\\\\\\\\ style comments, or change them to something like: /*----------- BOARD SETTINGS -----------*/

1
  • 1
    The \ at the end of the comment continues the current line onto the next one, so you get ///// comment \\\\\#ifdef... which comments out the #ifdef.
    – Majenko
    May 3 '17 at 17:18
0

If you remove backslashes at the end of comments on lines before #ifdefs, it will work just fine.

The gvim editor was much more helpful in that: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.