Go Down

Topic: commenting out #define causes error (Read 4 times) previous topic - next topic

strykeroz

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? 
Code: [Select]

// 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!
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Nick Gammon

<sigh>

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:

Code: [Select]
char foo;

strykeroz

You sir, are a lifesaver !  Thanks so much.

<sigh>
Sorry to cause that reaction, especially at this time of year.  My google-fu skills failed me clearly if it's a common issue.
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Nick Gammon

It's not your fault.

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

el_supremo

That problem and its solution should be a sticky!

Pete

Sergegsx

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.
* Si preguntas, pon el código de tu programa, hace mucho mas fácil ayudarte. Y me ahorro un mensaje pidiendo que lo hagas.
* Si consigues solucionar tu problema, dedica unos minutos a explicar en tu post como lo conseguiste para beneficio de todos.
* Cambia el 'Subject' de tu hilo y añade 'SOLUCIONADO' cuando hayas llegado a una solución al problema que planteaste.
* Utiliza un 'Subject' para tu hilo que explique de que va el hilo.
Si estas empezando:
* Comienza a usar Arduino
* Guías de iniciación a Arduino
* Ejemplos
* Referencia del Lenguaje
* Conceptos básicos
Guia de usuario de arduino
Tutoriales en Ingles
Si necesitas que alguien te escriba el código: http://www.freelancer.com/  o esta  http://www.guru.com/

pYro_65

Coincidentally you just pushed it above a thread with exactly the same error: http://arduino.cc/forum/index.php/topic,124904.msg938861.html#msg938861


That problem and its solution should be a sticky!

Pete


Funny stuff.

Go Up