beckhoff TE1200 — 8 Constant propagation

Constant propagation 8 Constant propagation | Constant propagation Available from TwinCAT 3.1.4026.14 Static code analysis is based on constant propagation, the results of which are used for various checks. For example, it checks whether pointers are not equal to 0 or whether array indices are outside the valid range. They can effectively support static analysis if they know how this analysis works and where its limits lie. See also: 'Show constant propagation values for current editor' command [ } 115] Constant propagation Static analysis attempts to determine the value of a variable based on its use. Sample: PROGRAM MAIN VAR x : INT; bTest :

BOOL; END_VAR x := 99; IF x bTest := TRUE; END_IF In the implementation in line 1, the constant propagation sets the value 99 for the variable x in order to use this value for further analyses. The analysis then recognizes that the expression in the subsequent IF statement is constantly TRUE. Locally performed constant propagation A value is only determined locally in the function block. It is irrelevant how an input is transferred. The results of function calls are also irrelevant. Sample: FUNCTION Func : BOOL VAR_INPUT bTest : BOOL; END_VAR IF bTest THEN Func := OtherFunc(TRUE); END_IF If the parameter bTest is set to TRUE for each call, this has no effect on the constant propagation.

Even if OtherFunc(TRUE) always returns TRUE, this has no effect on the constant propagation. Only temporary variables have initial values Static local variables in programs and function blocks do not have an assumed initial value. The variables retain their values from the last call and can therefore be "anything" in principle. Local variables in functions and temporary variables have an initial value each time they are called. The constant propagation calculates with this initial value. Sample: PROGRAM MAIN VAR x : INT := 6; bTest : BOOL; END_VAR VAR_TEMP y : INT := 8; END_VAR TE1200 126 Version: 2.11.1