Skip to content

Fix int documentation on overflow (which is UB) #23

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

Merged
merged 1 commit into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions Language/Variables/Data Types/int.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,8 @@ The Arduino takes care of dealing with negative numbers for you, so that arithme

[float]
=== Notes and Warnings
When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacity, note that this happens in both directions.
[source,arduino]
----
int x;
x = -32768;
x = x - 1; // x now contains 32,767 - rolls over in neg. direction
When signed variables are made to exceed their maximum or minimum capacity they _overflow_. The result of an overflow is unpredictable so this should be avoided. A typical symptom of an overflow is the variable "rolling over" from its maximum capacity to its minimum or vice versa, but this is not always the case. If you want this behavior, use link:unsignedInt{ext-relative}[unsigned int].

x = 32767;
x = x + 1; // x now contains -32,768 - rolls over

----
[%hardbreaks]

[float]
Expand Down
4 changes: 2 additions & 2 deletions Language/Variables/Data Types/unsignedInt.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ The difference between unsigned ints and (signed) ints, lies in the way the high

[float]
=== Notes and Warnings
When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacitiy, note that this happens in both directions
When unsigned variables are made to exceed their maximum capacity they "roll over" back to 0, and also the other way around:

[source,arduino]
----
unsigned int x
unsigned int x;
x = 0;
x = x - 1; // x now contains 65535 - rolls over in neg direction
x = x + 1; // x now contains 0 - rolls over
Expand Down