SA0133: Explicit narrowing conversions
Detects explicit conversions from a larger data type to a smaller data type
Justification: A large number of type conversions may indicate that you have chosen the wrong data types for variables. For this reason, there are programming guidelines that require an explicit justification for data type conversions.
Importance: Low
PROGRAM SA0133 VAR siVar:SINT; diVar:DINT; liVar:LINT; byVar:BYTE; uiVar:UINT; dwVar:DWORD; lwVar:LWORD; rVar:REAL; lrVar:LREAL; END_VAR
siVar := LINT_TO_SINT(liVar); // SA0133 byVar := DINT_TO_BYTE(diVar); // SA0133 siVar := DWORD_TO_SINT(dwVar); // SA0133 uiVar := LREAL_TO_UINT(lrVar); // SA0133 rVar := LWORD_TO_REAL(lwVar); // SA0133
Output in the Messages view:
SA0133: Explicit narrowing conversion from type 'LINT' to type 'SINT'
SA0133: Explicit narrowing conversion from type 'DINT' to type 'BYTE'
SA0133: Explicit narrowing conversions from type 'DWORD' to type 'SINT'
SA0133: Explicit narrowing conversion from type 'LREAL' to type 'UINT'
SA0133: Explicit narrowing conversion from type 'LWORD' to type 'REAL'