-
-
Notifications
You must be signed in to change notification settings - Fork 7k
ATtiny Compile Fail: Redefinition of preproc. symbol "BIN" (from "Stream.h" and "Print.h") by "iotnx4.h" #4784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I got the same error, but did not report it yet. I think there is almost no way to fix it instead of changing BIN to 7 and hope no other MCU defines this again. As it is used a kinda enum, there should be no problem in using number 7. |
Note that this is a warning, not an error and doesn't cause the compile to fail. I'm assuming you're using https://github.com/damellis/attiny but you'll also get this warning and #4785 with Arduino Gemma compiling a blank sketch. It seems like this warning could be fixed by changing cores\arduino\Print.h:32 to either: #undef BIN
#define BIN 2 (which will replicate the current behavior only without the warning) #ifndef BIN
#define BIN 2
#endif (which would retain the value set in iotnx4.h) |
Getting rid of the warning isn't the final goal. This can still cause weird errors if sometimes BIN (depending on which headers are included) is 2 and sometimes 7. Then the print will not work. And therefor there is a warning. I'd completely remove the BIN, make it depreciated and use something else. Also the BIN printing is almost useless to to very bad formatting. So one would rather use HEX (which still isnt perfect though). So in this case the 2nd solution would be better and at least keep the priority definition to the iotnx4 header. However I would still manually then insert a warning again, to remind the user of undefined behavior. |
@per1234 @NicoHood : thank you for your replies and your recommendations. |
Oh I wouldnt close this issue. I'd just use the warning and correct it this way, that if a conflict happens, the iotnx4 header has priority. It would look like this (inside print.h) // Special Attinyx4 definition conflict, give the internal iotnx4.h a higher priority
#ifndef BIN
#define BIN 2
#else
#warning Not using the correct BIN definition for print in this file! See #4784 on Github.
#endif |
@NicoHood Sorry for closing! I'm a github noob. |
Please test and post the output (for tinx4) You might also want to check if a normal compilation on an arduino uno works fine (without warning). Also test the printing of a variable via BIN). Its trivial, it should work though. |
@NicoHood As you recommended in your last two Posts... I've changed the "Print.h" as you mentioned before and tested this code first on Arduino/Genuino Uno (TEST_BIN_ON_ATTINY84 mus be commented), then tested it on ATtiny 84A (TEST_BIN_ON_ATTINY84 must be UNcommented). IMHO, it would be better to rename the symbol in the files "iotn84.h" and "iotnx4.h", from "BIN" to something else (like "IOTNX4_BIN"). The Change in "Print.h":
Used Code for testing:
Result of compilation for Arduino/Genuino Uno (Arduino IDE 1.6.7): Result of compilation for ATtiny 84A (Arduino IDE 1.6.7):
|
Great, thx for the report. Changing iotnx is impossible, as it is inside the avr library. avr-libc i think. What does |
ATtiny X4/X5 do not have hardware RS-232, so you have to include and use "SoftwareSerial.h". If you do this, you cannot use the standard "Serial" object (because the name is reserved by Arduino IDE), so you have to use other name like "mySerial" or in this case (my code above) "swSerial" to get rid of warnings/errors. I use the symbol "SERIAL_OBJ" to switch the name for µController architectures which does not have a hardware serial port. By the way... I never use "BIN" for output values, because it consumes "too much ressources" (specially on ATtiny25 and 45). As I've found that other developers also recommend to avoid using "BIN" for binary output. |
I know what your codes does and what it should output. But have you tested it? I am not sure that the correct values will be printed. |
Attiny chips can be used with external cores like |
And thatswhy we need this fix. Please reopen. |
I'm getting similar warnings when compiling for Digispark with ATTiny85:
|
In the current AVR core:
The solution proposed by @NicoHood in #4791: // Special Attinyx4 definition conflict, give the internal iotnx4.h a higher priority
#ifndef BIN
#define BIN 2
#else
#warning Not using the correct BIN definition for print in this file! See #4784 on Github.
#endif
IMHO it's better to keep the current value of BIN, even if it's wrong if used in the context of the #if defined(BIN)
#define AVR_BIN BIN
#undef BIN
#endif
#define BIN 2 |
Agreed on the former part of the analysis, changing it is not a really good idea. However, the proposed solution won't work, since preprocessor are evaluated lazily, in the sense that any macros inside a macro are only expanded after expanding the outer macro, not when defining it. E.g.:
|
Oh, I see, thanks for testing! then I'd remove the extra definition of #if defined(BIN)
#undef BIN
#endif
#define BIN 2 |
If you try to compile the code below for an ATtiny 84, you will get the error messages after the code.
The preprocessor symbol "BIN" used in "Stream.h" and "Print.h" (line 32, value=2) is redefined by "iotnx4.h" (line 71, value=7). Because "iotn84.h" includes "iotnx4.h" (line 38) the value of "2" is overwritten by "7"!
Quck-Fix / Workaround: if you don't use "BIN" in "print" or "println" statements like ("print(var, BIN)"), you can comment line 32 in "Print.h" to get rid of the error.
Used Environment: Win. 7 x64 Prof., Arduino IDE 1.6.7, ATtiny 84A, Arduino as ISP
START_OF_ERROR_OUTPUT -->
<-- END_OF_ERROR_OUTPUT
The text was updated successfully, but these errors were encountered: