Skip to main content

SA0014: Assignment of instances

Detects assignments to function block instances. In the case of instances with pointer or reference variables, these assignments are potentially risky.

Justification: This is a performance warning. When an instance is assigned to another instance, all elements and subelements are copied from the one instance to the other instance. 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, this kind of assignment could last a long time. For example, if an instance should be passed to a function for processing, then it is much more efficient to pass a pointer to the instance.

If you want to selectively copy values from one instance to another, then a copy method is useful:

inst_First.Copy_From(inst_Second)

Importance: Medium

Example 27. Example
PROGRAM PLC_PRG
VAR
    inst_First : My_FB;
    inst_Second : My_FB;
END_VAR
inst_First();
inst_Second := inst_First;  // SA0014

Output in the Messages view:

  • sa_icon_message.png SA0014: Assignment of instances