Pages: [1]   Go Down
Author Topic: #if strangness in the IDE  (Read 1574 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8821
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Guildford, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: