...
Nonportable Behavior | Definition | Annex J Section |
---|---|---|
Behavior for which the standard provides two or more possibilities and imposes no further requirements on which is chosen in any instance. | J.1 | |
Behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which the standard imposes no requirements. An example of undefined behavior is the behavior on integer overflow. | ||
Unspecified behavior whereby each implementation documents how the choice is made. | J.3 | |
Behavior that depends on local conventions of nationality, culture, and language that each implementation documents. | J.4 |
...
This noncompliant code example uses the complement operator in the test for unsigned integer overflow.:
Code Block | ||||
---|---|---|---|---|
| ||||
unsigned int ui1, ui2, sum; if (~ui1 < ui2) { /* Handle error condition */ } sum = ui1 + ui2; |
...
This compliant solution implements a strictly conforming test for unsigned overflow.:
Code Block | ||||
---|---|---|---|---|
| ||||
unsigned int ui1, ui2, sum; if (UINT_MAX - ui1 < ui2) { /* Handle error condition */ } sum = ui1 + ui2; |
...