Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E165 - Implicit conversion between BOOL and numbers

A number is assigned to a BOOL. The value is not limited to 0 and 1, so the result depends on the representation of the number. The literals 0 and 1 are accepted.

Code example:

PROGRAM mainProg
VAR
    flags : BYTE := 2;
    active : BOOL;
END_VAR
    active := flags;        // warning
    active := flags <> 0;
END_PROGRAM

To silence the warning, compare the number explicitly:

    active := flags <> 0;