#if strangness in the IDE

Why does the IDE always compile Wire in the following sketch independent of the value of USE_WIRE?

#define USE_WIRE 0

#if USE_WIRE
#include <Wire.h>
#endif

void setup() {
  Serial.begin(9600);
  Serial.println("why does the ide do this");
}
void loop() {}

If I comment out the include like this

//#include <Wire.h>

The sketch is 762 bytes smaller and Wire is no longer in the build folder.

I think it's the way the Arduino IDE saves people from having to specify the libraries to link with. It searches your sketch for includes and links with the associated library.

The IDE uses RegEx to find things that look like #include <blah.h> and then looks for all compilable files inside the library, then compiles them for you. It ignores other pre-processor but it stripes out all comments before doing the RegEx search

Too bad. That makes preprocessor directives usless around #includes.

You could create your own header and use conditional compilation inside that.

Create myheaders.h and put your conditional compilation directives / #includes in there.

You can still have the #define in the main file. Not as clear as your example but if you conditionals are well named it wouldn't be too confusing.

Iain

Thanks for trying to help with ideas like another include file. I understand ways to work around problems like this.

An IDE that implements a new language, "The Arduino programing language (based on Wiring)", should not be as flaky as this.

This is just one of many features/bugs that cause grief in the IDE. I posted this in the hope that someone in the Arduino group will improve the IDE.

Processing languages like this is not rocket science. Junior computer science students have learned this stuff from the Red Dragon Book since 1977. (Compilers: Principles, Techniques, and Tools by Aho, Sethi, and Ullman—also known as "The Red Dragon Book".)