



NOTICE

With compiler version >= V3.3.0.0, references are initialized (at 0).




NOTICE

If a reference refers to a device input, then the access is applied as write access.
When the code is generated, this leads to the compiler warning: "...invalid assignment target
".
Example: rInput REF= Input;
If you require a construct of this kind, you have to first copy the input value (example:
rInput
) to a variable with write access.
A reference with the REFERENCE
data type implicitly refers to another object. The assignment is done with the ⮫ REF= operator. When accessed, the reference is implicitly dereferenced, and therefore does not
need a special content operator ^
such as a pointer.
Syntax
<identifier> : REFERENCE TO <data type> ; <data type>: base type of the reference
Valid declaration
PROGRAM PLC_PRG VAR rspeA : REFERENCE TO DUT_SPECIAL; pspeA : POINTER TO DUT_SPECIAL; speB : DUT_SPECIAL; END_VAR rspeA REF= speB; // Reference rspeA is alias for speB. The code corresponds to pspeA := ADR(speB); rspeA := speD; // The code corresponds to pspeA^ := speD;
Invalid declarations
ariTest : ARRAY[0..9] OF REFERENCE TO INT; priTest : POINTER TO REFERENCE TO INT; rriTest : REFERENCE TO REFERENCE TO INT; rbitTest : REFERENCE TO BIT;
A reference type must not be used as the base type of an array, pointer, or reference. Furthermore, a reference must not refer to a bit variable. These kinds of constructs generate compiler errors.
The readability of a program is made difficult when the same memory cell is accessed simultaneously by means of an identifier and its alias.
Example: speB
and rspeA
References and pointers to BIT
variables are invalid declarations, as well as array elements with base type BIT
.
-
Comparison of reference and pointer
-
Testing the validity of a reference