You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Arduino.h always defines true and false, the trouble occurs when you use C, and include stdbool.h. Arduino.h should simply include stdbool.h instead of defining these for C code, and only define them if using C++.
Details: this seems to happen only for C code, not C++ or a sketch. I have situations where I write a library with mixed C and C++. This causes GCC to emit redefinition warnings.
The text was updated successfully, but these errors were encountered:
Arduino.h always defines true and false, the trouble occurs when you use C, and include stdbool.h. Arduino.h should simply include stdbool.h instead of defining these for C code, and only define them if using C++.
You say to only define them if using C++, but AFAIU they are language keyword in C++, so there is no need to define them (if you do, you'll be using integers instead of the actual true and false keywords, which will also work, but is not so nice).
So I think that we should just replace the true and false definitions with an #include <stdbool.h> and be done with it. For C, that will make true, false and bool available, for C++ that will just use the C++ keywords (stdbool.h contains a check for C vs C++).
In C++, true and false are language keywords, so there is no need to
define them as macros. Including stdbool.h in C++ effectively changes
nothing. In C, true, false and also the bool type are not available, but
including stdbool.h will make them available.
Using stdbool.h means that we get true, false and the bool type in
whatever way the compiler thinks is best, which seems like a good idea
to me.
This also fixes the following compiler warnings if a .c file includes
both stdbool.h and Arduino.h:
warning: "true" redefined [enabled by default]
#define true 0x1
warning: "false" redefined [enabled by default]
#define false 0x0
This fixesarduino#1570 and helps toward fixing arduino#1728.
This only changed the AVR core, the SAM core already doesn't define true
and false (but doesn't include stdbool.h either).
Arduino.h always defines true and false, the trouble occurs when you use C, and include stdbool.h. Arduino.h should simply include stdbool.h instead of defining these for C code, and only define them if using C++.
Details: this seems to happen only for C code, not C++ or a sketch. I have situations where I write a library with mixed C and C++. This causes GCC to emit redefinition warnings.
The text was updated successfully, but these errors were encountered: