SA0125: References in initializations
Detects reference variables which are used for initialization in the declaration part
Justification: Pointers and references should not be used for initializations because this can lead to access violations if the pointer has not been initialized.
Importance: Medium
Example 112. Example
TYPE TESTSTRUCT : STRUCT xA : BOOL; xB : BOOL; END_STRUCT END_TYPE
FUNCTION_BLOCK FB_Test VAR_INPUT refTeststruct: REFERENCE TO TESTSTRUCT; END_VAR VAR xA : BOOL := refTeststruct.xA; //SA0125 END_VAR
xA := TRUE;
PROGRAM PLC_PRG VAR fbTest : FB_Test; END_VAR
fbTest();
Output in the Messages view:
SA0125: Reference used in initialisation