Insert the pragma {attribute 'no assign'} as first line of the declaration part of a function block. This has the effect that compile errors are generated if an instance of the function block is assigned to another instance of the same function block. For example, you might want to avoid such assignments if the function block contains pointers. This could cause issues because they are copied when values are assigned.
NOTE: Use the {attribute 'no assign'} in function blocks with internal pointers to help to avoid assigning an instance of the function block to another instance of the same function block.
Assignment of Function Block Instances Containing Pointers
In this example, the value assignment of function block instances causes issues when fb_exit is executed:
VAR_GLOBAL
inst1 : TestFB;
awsBufferLogFile : ARRAY [0..9] OF WSTRING(66);(* Area: 0, Offset: 0x1304 (4868)*)
LogFile : SEDL.LogRecord := (sFileName := 'LogFile.log', pBuffer := ADR(awsBufferLogFile), udiMaxEntriesFile := UDINT#10000, udiMaxBuffered := UDINT#10, uiLineSize := UINT#64, wsSep := " ", xCircular := TRUE, siDateFormat := SINT#0, siTimeFormat := SINT#0);
END_VAR
PROGRAM PLC_PRG
VAR
inst2 : TestFB := inst1;
LogFileNew : LogRecord := LogFile;
END_VAR
In this case, LogRecord manages a list of pointers. Different actions are executed for them if fb_exit applies. When assigning function block instances, fb_exit will be executed twice which causes an issue. Prevent this by adding the no_assign attribute to the declaration of function block TestFB:
{attribute 'no_assign'}
FUNCTION_BLOCK TestFB
VAR_INPUT
...
The following compile errors are reported:
C0328: Assignment not allowed for type TestFB
C0328: Assignment not allowed for type LogRecord