Attribute ‘no_assign’¶
This pragma causes compiler errors to be displayed if an instance of the function block is assigned to another instance of the same function block. Such assignments are often to be avoided if the function block contains pointers and pointers lead to problems, because they are copied as well during the value assignment.
Syntax:
{attribute 'no_assign'}
Insertion position: first line in the declaration part of a function block.
Example
Assignment of function block instances containing pointers.
In this example the value assignment of the function block instances will lead to problems during the execution of fb_exit
:
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
END_VAR
In this case LogRecord
manages a list of pointers, for which various actions are executed in the case of fb_exit
. Problems result due to the assignment, because fb_exit
will be executed twice. You should prevent this by adding the attribute 'no_assign'
in the declaration of the function block TestFB:
{attribute 'no_assign'}
FUNCTION_BLOCK TestFB
VAR_INPUT
...
The following compile errors are then displayed:
C0328: Assignment not allowed for type TestFB
C0328: Assignment not allowed for type LogRecord