Skip to main content

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

Example 56. Example
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:

  • sa_icon_message.png SA0133: Explicit narrowing conversion from type 'LINT' to type 'SINT'

  • sa_icon_message.png SA0133: Explicit narrowing conversion from type 'DINT' to type 'BYTE'

  • sa_icon_message.png SA0133: Explicit narrowing conversions from type 'DWORD' to type 'SINT'

  • sa_icon_message.png SA0133: Explicit narrowing conversion from type 'LREAL' to type 'UINT'

  • sa_icon_message.png SA0133: Explicit narrowing conversion from type 'LWORD' to type 'REAL'