edward0429 / arduino

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

Don't expose PA, PB, ... PL, etc constants in the header file. #677

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
From Paul Stoffregen:

"Today I discovered a library which uses a variable named "PL" internally.  
That won't compile on 1.0-rc1, due to this new definition inside Arduino.h.

#define PL 12

These appear to be used only internally within the new pins_arduino.h in the 
variants folder.  The appear to only be needed when compiling main, when 
ARDUINO_MAIN is defined.

An easy way to avoid these conflicting with user variable names would be to 
only define them when ARDUINO_MAIN is defined.  For example:

#ifdef ARDUINO_MAIN
#define PA 1
#define PB 2
#define PC 3
#define PD 4
#define PE 5
#define PF 6
#define PG 7
#define PH 8
#define PJ 10
#define PK 11
#define PL 12
#endif"

Original issue reported on code.google.com by dmel...@gmail.com on 11 Oct 2011 at 3:26

GoogleCodeExporter commented 8 years ago
Defines which are only needed in the Arduino core should not be exposes in the 
most-public-of-all new "Arduino.h" header.

Another way to fix this is to place such definitions as enums inside a C++ 
class or namespace called "Arduino".

The whole "Arduino.h" header is a minefield - unfortunately it's not limited to 
all-caps defines, as in the AVR headers: #undef abs, #define true - it all 
seems to have been written by a megalomaniac mind... (or more likely by someone 
who never expected this code to become as central and widespread as it has).

The right thing to do IMNSHO, is to call off 1.0 and rethink all the major 
issues first. Calling this code base 1.0 just sets the stage for a much bigger 
long-term mess. Show some vision and courage, and just call it 0023.

Original comment by jc@wippler.nl on 15 Oct 2011 at 9:48

GoogleCodeExporter commented 8 years ago
I applied Paul's suggestion.  Other patches to make the header file less 
problematic are welcome; please open an issue for them.  

https://github.com/arduino/Arduino/commit/f729e0321b864bac6cc52a4adde5f7b059d85c
68

Original comment by dmel...@gmail.com on 24 Oct 2011 at 8:52