commenting out #define causes error

Hi,

I have a project with a lot of large constant strings, so thought I'd offload them to EEPROM and only address the ones I need in limited scopes as I need them.

To do this I thought I'd have a "#define SETUPMODE" which could be commented out after the sketch had been run once and all those strings would be gone, replaced by addresses in EEPROM to save space. Problem is when I comment out that line the compiler gives an error in the first line of setup(), 'Serial' was not defined in this scope. I simplified the sketch to illustrate the point, and the below simplified version does the same.

With the SETUPMODE definition it runs, without, it doesn't compile.

Any ideas why this might be?

// comment this line to put in RUN mode
#define SETUPMODE
// comment this line to remove USB debug printlns
#define DEBUG
// debugging functions controlled by the above definition
#ifdef DEBUG
  #define DEBUG_PRINT(x)     Serial.print (x)          // print text to USB
  #define DEBUG_PRINTDEC(x)     Serial.print (x, DEC)  // print value to USB
  #define DEBUG_PRINTLN(x)  Serial.println (x)         // print text with newline to USB
#else
  #define DEBUG_PRINT(x)
  #define DEBUG_PRINTDEC(x)
  #define DEBUG_PRINTLN(x)
#endif

/* this block only present if in Setup mode - once Setup has been run once, 
all these values are safely stored in the Arduino's onboard EEPROM. */
#ifdef SETUPMODE
// declare things that only get used for setupmode
  int testvar = 5;
#endif

// global scop declarations common to RUN and SETUPMODE go here
  int testval = 5;
  
void setup() {
  Serial.begin(9600);  // for talking with Arduino IDE over USB
  
#ifdef SETUPMODE
    Serial.println("Setup mode enabled.");
#else
  Serial.println("Standard mode enabled.");
#endif
}

void loop() {
  
  #ifdef SETUPMODE
    Serial.println("Setup complete, comment out #define SETUPMODE in sketch and re-upload to Arduino.");
  #endif
  for(;;);   // do nothing, forever
  
}

I have a sneaking suspicion I've been staring at the reason all night so hoping fresh eyes will see!

It's something to do with the way the IDE preprocesses your code.

If you add this line to the very start, the error goes away:

char foo;

You sir, are a lifesaver ! Thanks so much.[quote author=Nick Gammon link=topic=84412.msg632518#msg632518 date=1324708154]

[/quote]Sorry to cause that reaction, especially at this time of year. My google-fu skills failed me clearly if it's a common issue.

It's not your fault.

I was sighing because the IDE design causes some unexpected issues like this.

That problem and its solution should be a sticky!

Pete

Wanted to thank you for this cause I was going crazy about this error.
hope it is Ok to push it up, it might help other people.

Coincidentally you just pushed it above a thread with exactly the same error: Error compiling - Programming Questions - Arduino Forum

el_supremo:
That problem and its solution should be a sticky!

Pete

Funny stuff.