Skip to main content

SA0008: Check subrange types

Detects out-of-range violations of subrange types. Assigned literals are already checked by the compiler. When constants are assigned, then the values must be within the defined range. When variables are assigned, then the data types must be identical.

Justification: If subrange types are used, then make sure that this subrange is not exited. The compiler checks for these kinds of subrange violations only for assignments of constants.

Importance: Low

Tip

The check is not performed for CFC objects because the code structure does not allow it.

Example 20. Example
VAR_GLOBAL
    iVarGlob:INT;
END_VAR
PROGRAM PLC_PRG
VAR
    iSubr1: INT (INT#1..INT#10);
    iSubr2: INT (INT#1..INT#1000);
    iCount: INT;
    by_SubType : BYTE (BYTE#0..BYTE#11);
    iVar : INT (-4095..4095);
END_VAR
iSubr1 := nCount;              // SA0008
iSubr1 := subr2;               // SA0008
iSubr1 := gvl.iVarGlob;        // SA0008
//byBYTE_SubType := BYTE#123;  //already detected by compiler, error "Cannot convert type..."

Output in the Messages view:

  • sa_icon_message.png SA0008: Subrange variable 'iSubr1' maybe out of allowed range