MUTABLE |
Top Previous Next |
MUTABLE is an attribute that can be used on variables that are declared in a VAR_INPUT section of a function block or a thread block. By using this attribute it is legal to assign a value to this variable from inside the function block / thread block. The MUTABLE attribute can only be used on variables of simple data types.
This is a simple example of using mutable variables:
FUNCTION_BLOCK CB_TEST; VAR_INPUT v1 : MUTABLE INT; v2 : MUTABLE STRING; v3 : INT; END_VAR; v1 := v1 * 5; v2 := "Hello world"; v3 := 51; <--- NOT ALLOWED END_FUNCTION_BLOCK;
VAR test : CB_TEST; END_VAR;
Calling the function block:
test( v1 := 1, v2 := "Nice", v3 := 1 );
After the call to "test", the contents of the input variables are as follows: "v1" is 5, "v2" is "Hello world", and "v3" is 1. "v1" and "v2" are both mutable and their values are therefore changed, while "v3" is not mutable and its contents remain unchanged.
|