Versions Compared

Key

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

Errors in C, C++, and other programming languages often result when a programmer fails to consider all possible data states. 

Non-

...

Compliant Code Example

The following This example fails to tests for conditions where a is neither b nor c. This may be the correct behavior in this case, but failure to account for all the values of a may result in logic errors if a unexpectedly assumes a different value.

Code Block
...
if (a == b) {
  ...
}
else if (a == c) {
  ...
}
...

Compliant Solution

The following This compliant solution explicitly checks for the unexpected condition and handles it appropriately.

Code Block
...
if (a == b) {
  ...
}
else if (a == c) {
  ...
}
else {
  assert( (a==b) || (a == c) );
  abort();
}
...

Non-

...

Compliant Code Example

The following This example fails to consider all possible cases. This may be the correct behavior in this case, but failure to account for all the values of a may result in logic errors if a unexpectedly assumes a different value.

Code Block
...
switch(a) {
  case: 1
    break;
  ...
}
...

Compliant Solution

The following This compliant solution explicitly checks for the unexpected condition and handles it appropriately.

...