-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Arduino.h boolean type #5440
Comments
I wholeheartedly agree with this. However, I've come across way too many libs out there that use boolean, and those would break. |
I think you may also break alignments in structs. |
That is correct. Also, structs written to/read from EEPROM and rtcmem. |
We discussed this on gitter and also did some checks in GCC code and our own tests.
So alignment issues should not be a problem. There is still some concern about value interpretation, but I think that's actually the point of this bug, where |
|
In GCC compiler source code when Even Some of the confusion may be that the linker will place consecutive |
Generates:
|
I just did a test with these: typedef struct {
boolean b;
boolean c;
boolean d[16];
uint16_t u;
} __attribute__((__packed__)) s_bp;
typedef struct {
bool b;
bool c;
bool d[16];
uint16_t u;
} __attribute__((__packed__)) s_cp; With only bool/boolean b & c, both reported an offset of 2. |
So there are no mis-alignment issue. |
Match current Arduino definition to avoid issues with comparison operations. arduino/Arduino#2147 arduino/Arduino@20ac20f Fixes esp8266#5440
Match current Arduino definition to avoid issues with comparison operations. arduino/Arduino#2147 arduino/Arduino@20ac20f Fixes #5440
Basic Infos
Platform
Settings in IDE
Problem Description
I had noticed that the
boolean
is typedefed touint8_t
, notbool
as one would think:Arduino/cores/esp8266/Arduino.h
Line 191 in d5d1126
Arduino base repo had an issue about this problem: arduino/Arduino#2147
Gist of the original issue is that boolean & bool comparison through == may yield different than expected results. Just like this wiki article describes benefits of having native
bool
vs. implementing it through int: https://en.wikipedia.org/wiki/Boolean_data_type#C,_C++,_Objective-C,_AWKAVR, SAMD etc. Cores have it typedef'd to bool since. After that, arduino/Arduino#4673 was raised about replacing boolean with bool all throughout the Cores.
So my questions are:
MCVE Sketch
From the issue mentioned above, slightly modified for verbosity.
Conditions resolve the same ofc.
Debug Messages
The text was updated successfully, but these errors were encountered: