Versions Compared

Key

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

...

Code Block
bgColor#FFcccc
signed long sl1, sl2, result;

result = sl1 % sl2;

Implementation Details

On MSVC++, taking the modulo of INT_MIN by -1 yields the value 0.

On gcc/Linux, taking the modulo of INT_MIN by -1 produces a floating-point exception.

Compliant Solution

This compliant solution tests the modulo operand to guarantee there is no possibility of a divide-by-zero error or an overflow error.

...