-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Modified Arduino.h with changes to the boolean type #2151
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
Conversation
As the Arduino specific boolean type is dangerous in C++, I have implemented a fix to solve the situation for both C and C++ There is also no need for stdbool, it also defines true and false, which is not needed or allowed in a C++ context.
I have modified the code to only have the changes. I also replied here #2147 (comment) as to why my idea is worth implementing. For the features stdbool provides, I recommend adding it to only add in C if it must be used, there is no reason to change the current bool, true, or false in C++. And simply to avoid compilation overhead it can be left out altogether, Arduino.h does get included extensively. Also you pointed out that |
Also, if you'd rather keep the stdbool functionality, I can modify my pull request to leave it in. |
@@ -32,6 +31,14 @@ | |||
#include "binary.h" | |||
|
|||
#ifdef __cplusplus | |||
typedef bool boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the important part of my addition. The boolean type needs to be seen as a bool when compiling C++ code.
This update will allow the String class to be used in a range based for loop.
Can one of the admins verify this patch? |
I think that stdbool.h should be used, as it will actually do the right thing. |
Stdbool.h doesn't really solve anything though. As you can see its the typedef in Arduino.h which is the problem. |
Yes, but is the type correct? I can't tell from the diff. |
It effectively adds this: #ifdef __cplusplus
typedef bool boolean;
#else
typedef uint8_t boolean;
#define false 0
#define true !false
#endif So in C++ Basically I do not mind how this is implemented, I just insist that the Arduino custom type be a real
Also stdbool.h uses a GCC specific The third commit doesn't belong here, If this fix is going to be used I will remove it and merge the remaining commits once I can get Arduino cloned on my PC. |
I wouldn't worry so much with porting. I highly doubt the Arduino team will On Sun, Dec 21, 2014 at 7:33 AM, Christopher Andrews <
Visit my github for awesome Arduino code @ https://github.com/xxxajk |
From: it seems that
So it's sufficient to include #define bit(b) (1UL << (b))
-typedef uint8_t boolean;
+typedef bool boolean;
typedef uint8_t byte;
void init(void); What do you think? |
That is exactly what I was saying :-) On Tue, Jan 6, 2015 at 4:43 PM, Cristian Maglie notifications@github.com
Visit my github for awesome Arduino code @ https://github.com/xxxajk |
+1 |
FWIW, I merged a version for this fix on Teensy, using this:
|
@cmaglie That is excellent. All that is important to me is correct semantics in C++. Sorry @xxajk, the GCC documentation led me to believe it was an extension/GCC only. |
Fixed with 20ac20f |
As the Arduino specific boolean type is dangerous in C++, I have implemented a fix to solve the situation for both C and C++ There is also no need for stdbool, it also defines true and false, which is not needed or allowed in a C++ context.
This is in reference to the issue I posted here.
#2147