SA0130: Implicit expanding conversions
Function | Determines code positions where conversions from smaller to larger data types are implicitly carried out during arithmetic operations. |
Reason | The compiler allows any assignment of different types if the range of the source type is fully within the range of the target type. However, the compiler will build a conversion into the code as late as possible. For an assignment of the following type:
the compiler performs the implicit conversion only after the multiplication:
An overflow is therefore truncated. If you want to prevent this, you can have the conversion performed earlier for the elements:
Therefore, it may be useful to report points where the compiler implements implicit conversions in order to check whether these are exactly what is intended. In addition, explicit conversions can serve to improve portability to other systems if they have more restrictive type checks. |
Exception | BOOL ↔ BIT |
Importance | Low |
Samples:
PROGRAM MAIN
VAR
nDINT : DINT;
nLINT : LINT;
nUSINT : USINT;
nUINT : UINT;
nUDINT : UDINT;
nULINT : ULINT;
nLWORD : LWORD;
fLREAL : LREAL;
nBYTE : BYTE;
END_VARnDINT := UINT_TO_DINT(nUINT) * UINT_TO_DINT(nUINT); // no error
nDINT := nUINT * nUINT; // => SA0130
nLINT := nDINT * nDINT; // => SA0130
nULINT := nUSINT * nUSINT; // => SA0130
nLWORD := nUDINT * nUDINT; // => SA0130
fLREAL := nBYTE * nBYTE; // => SA0130