SA0015: Access to global data via FB_init

Function

Determines access of a function block to global data via the FB_init method. The value of this variables depends on the order of the initializations!

Reason

Depending on the declaration location of the instance of a function block, a non-initialized variable may be accessed if the rule is violated.

Importance

High

Sample:

Global variable list GVL_App:

VAR_GLOBAL
    nVar      : INT;
END_VAR

Function block FB_Sample:

FUNCTION_BLOCK FB_Sample
VAR
    nLocal    : INT;
END_VAR

Method FB_Sample.FB_init:

METHOD FB_init : BOOL
VAR_INPUT
    bInitRetains  : BOOL;        // if TRUE, the retain variables are initialized (warm start / cold start)
    bInCopyCode   : BOOL;        // if TRUE, the instance afterwards gets moved into the copy code (online change)
END_VAR
nLocal := 2*nVar;                // => SA0015

MAIN program:

PROGRAM MAIN
VAR
    fbSample  : FB_Sample;
END_VAR