beckhoff TE1200 — 4.2.1.1.14 SA0014: Assignments of instances

Configuration | Rules PROGRAM MAIN VAR nSample : INT := INT#17; nVar : INT; END_VAR nVar := nVar + nSample; // => SA0012 4.2.1.1.13 SA0013: Declarations with the same variable name | SA0013: Declarations with the same variable name Samples: Global variable list GVL_App: VAR_GLOBAL nVar : INT; END_VAR MAIN program, containing a method with the name Sample: PROGRAM MAIN VAR bVar : BOOL; nVar : INT; // => SA0013 Sample : DWORD; // => SA0013 END_VAR .nVar := 100; // Writing global variable "nVar" nVar := 500; // Writing local variable "nVar" METHOD Sample VAR_INPUT 4.2.1.1.14 SA0014: Assignments of instances | SA0014: Assignments of instances Sample: PROGRAM MAIN VAR fb1 : FB_Sample; fb2 :

FB_Sample; END_VAR fb1(); fb2 := fb1; // => SA0014 TE1200 26 Version: 2.11.1 Function Determines variables with the same name as other variables (example: global and local variables with the same name), or the same name as functions, actions, methods or properties within the same access range. Reason Identical names can be confusing when the code is read and can lead to errors if the wrong object is accessed accidentally. We therefore recommend using naming conventions that avoid such situations. Importance Medium PLCopen rule N5/N9 Function Determines assignments to function block instances. For instances with pointer or reference variables such assignments may be risky.

Reason This is a performance warning. When an instance is assigned to another instance, all elements and sub elements are copied from one instance to the other. Pointers to data are also copied, but not their referenced data, so that the target instance and the source instance contain the same data after the assignment. Depending on the size of the instances, such an assignment may take a long time. If, for example, an instance is to be passed to a function for processing, it is much better to pass a pointer to the instance. A copy method can be useful for selectively copying values from one instance to another: fb2.CopyFrom(fb1) Importance Medium