Skip to main content

IAR Embedded Workbench for Arm 9.70.x

Detecting division by zero

In this section:
Description

Checks for division by zero and modulo by zero. Floating-point operations are checked for division by exactly (positive) zero.

Why perform the check

Because the behavior of integer division by zero is undefined, and because floating-point division by exactly zero usually indicates a problem.

How to use it

Compiler option: ‑‑runtime_checking div_by_zero

In the IDE: Project>Options>Runtime Checking>Division by zero

The check can be applied to one or more modules.

How it works

The compiler inserts code to perform the check at each division and modulo operation, unless the compiler determines that the check cannot fail.

Example

Follow the procedure described in Getting started using C-RUN runtime error checking, but use the Division by zero option.

This is an example of source code that will be identified during runtime:

crs_div_zero_Hom7.1_M16_1.PNG

C-RUN will report Division by zero. This is an example of the message information that will be listed:

message_div_zero_Hom7.1_M16_1.PNG