Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Nonportable Behavior

Definition

Annex J Section

unspecified Unspecified behavior

Behavior for which the standard provides two or more possibilities and imposes no further requirements on which is chosen in any instance.

J.1

undefined Undefined behavior

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.

J.2

implementationImplementation-defined behavior

Unspecified behavior whereby each implementation documents how the choice is made.

J.3

localeLocale-specific behavior

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
bgColor#FFCCCC
langc
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
bgColor#ccccff
langc
unsigned int ui1, ui2, sum;

if (UINT_MAX - ui1 < ui2) {
  /* Handle error condition */
}
sum = ui1 + ui2;

...