Convention: Input Variable Read Check

User Description

In the declaration part of a program, function block, method, or function, input variables can be defined. When objects of this type are called, input values must be specified. When a method or a function is called, the input values are copied to the stack. These values (memory area) are only used by the method or function call.

Compared to programs where exactly one instance exists in memory (or function blocks which are instantiated multiple times in memory), the programs or function blocks can be called multiple times, by multiple tasks, and the same memory location for the input variable is used (in parallel).

For application execution stability, the input variable should not be read from outside the program or function block.

NOTE: Keep in mind that access to an input variable from a method defined below a function block is also considered as access from outside the function block. The convention violation of the input Variable Read Check could be a false positive, if the developer verifies, for example, by code review, that the input variable is initialized before using it in a method.

Convention Verification Rule

Each read access to an input variable from outside the function block (body) or program (body) implementation itself is reported as convention violation.

Example

SR_Main
VAR
   fbTest: FB_Test;
END_VAR

// call of FB method without calling FB (Body) before
fbTest.Meth();


FB_Test
VAR_INPUT
   i_lrCurrentAxisPosition: LREAL;
END_VAR


METHOD Meth()
VAR
   i_lrVar1: LREAL;
END_VAR

// potential access to not properly initialized variable
i_lrVar1 := i_lrCurrentAxisPosition;