E161 - Operand converted to a type of the other sign
An operation combines a signed and an unsigned operand, so the compiler converts the unsigned operand to
the signed type that the operation works in. If the signed type cannot hold every value of the unsigned
type, the conversion may change the value of the operand. For example, comparing a DINT with a UDINT
reads the UDINT as a DINT, so 3000000000 becomes -1294967296. Bit types (BYTE, WORD, DWORD,
LWORD) count as unsigned.
Code example:
PROGRAM mainProg
VAR
signed : DINT := 1;
unsigned : UDINT := 3000000000;
result : BOOL;
END_VAR
result := signed < unsigned; // warning: UDINT is converted to DINT, result is FALSE
END_PROGRAM
To silence the warning, convert both operands to a type that holds every value of both:
result := DINT_TO_LINT(signed) < UDINT_TO_LINT(unsigned);
When the result of the operation is assigned, it is not reported again by E160.