Skip to content

Commit fbfc3e9

Browse files
authored
Merge pull request #23 from cousteaulecommandant/master
Fix `int` documentation on overflow (which is UB)
2 parents 1d30559 + 7a317a1 commit fbfc3e9

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

Language/Variables/Data Types/int.adoc

+1-10
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,8 @@ The Arduino takes care of dealing with negative numbers for you, so that arithme
5959

6060
[float]
6161
=== Notes and Warnings
62-
When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacity, note that this happens in both directions.
63-
[source,arduino]
64-
----
65-
int x;
66-
x = -32768;
67-
x = x - 1; // x now contains 32,767 - rolls over in neg. direction
62+
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].
6863

69-
x = 32767;
70-
x = x + 1; // x now contains -32,768 - rolls over
71-
72-
----
7364
[%hardbreaks]
7465

7566
[float]

Language/Variables/Data Types/unsignedInt.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ The difference between unsigned ints and (signed) ints, lies in the way the high
5252

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

5757
[source,arduino]
5858
----
59-
unsigned int x
59+
unsigned int x;
6060
x = 0;
6161
x = x - 1; // x now contains 65535 - rolls over in neg direction
6262
x = x + 1; // x now contains 0 - rolls over

0 commit comments

Comments
 (0)