smarques7 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 1 forks source link

Consider including WProgram.h from the avr-gcc command line #156

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by dmel...@gmail.com on 22 Dec 2009 at 9:47

GoogleCodeExporter commented 9 years ago
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.

Original comment by ben.combee on 22 Dec 2009 at 10:33

GoogleCodeExporter commented 9 years ago
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.

Original comment by jeffrowb...@gmail.com on 6 Oct 2010 at 3:42