I'm putting together a simple sketch to read a few sensors and have come across some odd behaviour associated with #define
and #ifdef
.
Here are some snippets from my code:
// Defines
//#define DEBUG 1
#define ACCELEROMETER 1
#define GYROSCOPE 1
#define GPSSYSTEM 1
#ifdef GPSSYSTEM
unsigned int Mth=0;
unsigned int Day=0;
char TMZ[2];
#endif
With this snippet the rest of the sketch compiles, but with this:
// Defines
//#define DEBUG 1
#define ACCELEROMETER 1
#define GYROSCOPE 1
//#define GPSSYSTEM 1
#ifdef GPSSYSTEM
unsigned int Mth=0;
unsigned int Day=0;
char TMZ[2];
#endif
The compile fails, claiming that the error is in some functions further down.
BTW, Mth
, Day
and TMZ
are not used anywhere yet, not are they defined anywhere else. What is even more odd is that the error messages are announcing the erroneous line numbers to be about 12 lines removed from where they really exist in the sketch, and have no association with the declarations here.
Now, this gives a clean compile:
// Defines
//#define DEBUG 1
#define ACCELEROMETER 1
#define GYROSCOPE 1
#define GPSSYSTEM 1
//#ifdef GPSSYSTEM
unsigned int Mth=0;
unsigned int Day=0;
char TMZ[2];
//#endif
as does this:
// Defines
//#define DEBUG 1
#define ACCELEROMETER 1
#define GYROSCOPE 1
//#define GPSSYSTEM 1
//#ifdef GPSSYSTEM
unsigned int Mth=0;
unsigned int Day=0;
char TMZ[2];
//#endif
I've been chasing this weirdness for a day now and am getting nowhere.