|Issue 156:||Consider including WProgram.h from the avr-gcc command line|
|5 people starred this issue and may be notified of changes.||Back to list|
What change would like to see? Include WProgram.h using a command line argument to avr-gcc instead of inserting it into the source code of the user sketch. Why? To prevent pre-processing errors, like the one described at: <http://www.arduino.cc/cgi- bin/yabb2/YaBB.pl?num=1261506776> (the #include ends up within a false #ifdef). Would this cause any incompatibilities with previous versions? If so, how can these be mitigated? It would prevent people from using #defines to influence the behavior of the code in WProgram.h, although it's not clear if anyone does this.
Dec 22, 2009
I've seen issues with some of the macros in WProgram.h and standard header files like <stdlib.h>. If you include stdlib.h after WProgram.h has been included, you'll get hard to figure-out compilation errors. I'd love to see WProgram implicitly included through the command line, but it would be good to clean it up so it's a good citizen with the standard library first.
Oct 5, 2010
I just had to work around an error caused by this problem. My code has an #ifdef near the beginning which includes a variable declaration inside the conditional code block. If I didn't define the constant, then the IDE-inserted #include was incorrectly inserted inside that block, and consequently never compiled in the first place. For example: --- START CODE --- //#define ENABLE_PS2 //#define ENABLE_USB //#define ENABLE_BLUETOOTH #ifdef ENABLE_PS2 #include "ps2keyboard.h" #define KB_PIN_CLOCK 3 #define KB_PIN_DATA 2 PS2keyboard *keyboard; #endif --- END CODE --- I was able to easily work around this so the program compiled as expected by changing my code to include a dummy variable up above, like so: --- START CODE --- unsigned char ide_workaround = 0; //#define ENABLE_PS2 //#define ENABLE_USB //#define ENABLE_BLUETOOTH #ifdef ENABLE_PS2 #include "ps2keyboard.h" #define KB_PIN_CLOCK 3 #define KB_PIN_DATA 2 PS2keyboard *keyboard; #endif --- END CODE --- Easy, but it should be unnecessary, and I wouldn't have known to try it if not for other posts in the Arduino forums. They said the regexes responsible for figuring out where to put the #include directive weren't totally reliable.
|► Sign in to add a comment|