The pragma 'no_assign'
results in compiler errors being 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.
The pragma 'no_assign_warning'
results in the same as for the pragma 'no_assign'
with compiler warnings instead of compiler errors.
Syntax:
{attribute 'no_assign'}
Insert location: 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 compiler errors are then displayed:
C0328: Assignment not allowed for type TestFB C0328: Assignment not allowed for type LogRecord
If the pragma no_assign_warning
is used instead of the pragma no_assign
for the function block “TestFB ”, then the C0328
message is issued as compiler warning, not as a compiler error.