-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Fix documentation about int "roll over" #4987
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
Can you please provide and example to show this? Did you notice this only on AVR or also on SAM and SAMD? |
It should affect both AVR and SAM. Bug #4511 explains this issue in detail. Here's an example snippet:
I don't have a physical Arduino to try this right now (neither AVR nor ARM/SAM), but enabling the
Basically, "this should not happen" when you're writing a C++ (or C) compliant program; doing so is forbidden according to the standard, so the compiler is free to assume that it will never happen when optimizing the code (which happens with GCC provides a PS: as I said I haven't physically tested this code snippet (although I did back in the day), and undefined behavior being undefined behavior it might be possible that it does something unexpected such as working. |
Documentation is fixed, let's continue on #4624 about |
Currently the documentation for
int
claims thatint
wraps when overflowing. This is not the case; signed integer overflow is undefined behavior and the GCC compiler used by Arduino may do weird things (see bug #4511).This bug would be solved by pull request #4624, but until it is accepted, it would be nice to change the documentation and remove the whole "coding tip" paragraph (or at least leave it commented until Arduino handles it as the documentation claims).
I already requested this on arduino/reference-en#23 but apparently this repository is more appropriate for requesting documentation changes.
The text was updated successfully, but these errors were encountered: