Go Down

Topic: #if strangness in the IDE (Read 1 time) previous topic - next topic

fat16lib

Apr 08, 2011, 09:02 pm Last Edit: Apr 08, 2011, 09:03 pm by fat16lib Reason: 1
Why does the IDE always compile Wire in the following sketch independent of the value of USE_WIRE?
Code: [Select]
#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
Code: [Select]
//#include <Wire.h>
The sketch is 762 bytes smaller and Wire is no longer in the build folder.

johnwasser

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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

frank26080115

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
Freelance engineer, consultant, contractor. Graduated from UW in 2013.

fat16lib

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

sixeyes

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

fat16lib

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".)

Go Up