Attribute 'no_assign', Attribute 'no_assign_warning'

Attribute 'no_assign', Attribute 'no_assign_warning' 1:

Available from TwinCAT 3.1 Build 4026

The 'no_assign' pragma causes compiler errors to be issued when an instance of the function block is assigned to another instance of the same function block. Assignments like these should be avoided where possible if the function block contains pointers, as the pointers copied with the assignment lead to problems.

The 'no_assign_warning' pragma has the same effect as the 'no_assign' pragma but there is one difference: a compiler warning is issued instead of a compiler error.

Syntax: {attribute 'no_assign'} or {attribute 'no_assign_warning'}

Insertion location: First line in the declaration part of a function block

Sample:

As the FB_Test function block contains pointers, assignment of a function block instance should be avoided by adding the 'no_assign' attribute in the declaration of the FB_Test function block:

{attribute 'no_assign'}
FUNCTION_BLOCK FB_Test
VAR
    pVar    : POINTER TO LREAL;

Assignment of function block instances:

VAR_GLOBAL
    fbInst1 : FB_Test;
END_VAR
PROGRAM MAIN
VAR
    fbInst2 : FB_Test := fbInst1;
END_VAR

Then the following compiler error is output:

Assignment not allowed for type FB_Test