You can use the operator __ISVALIDREF
to check whether or not a reference points to a valid value (meaning a value not
equal to 0).
Syntax
<boolean variable name> := __ISVALIDREF( <reference name> );
<reference name>
: Identifier declared with REFERENCE TO
The Boolean variable is TRUE
when the reference points to a valid value. Otherwise it is FALSE
.
Example
PROGRAM PLC_PRG VAR iAlfa : INT; riBravo : REFERENCE TO INT; riCharlie : REFERENCE TO INT; bIsRef_Bravo : BOOL := FALSE; bIsRef_Charlie : BOOL := FALSE; END_VAR iAlfa := iAlfa + 1; riBravo REF= iAlfa; riCharlie REF= 0; bIsRef_Bravo := __ISVALIDREF(riBravo); (* becomes TRUE, because riBravo references to iAlfa, which is non-zero *) bIsRef_Charlie := __ISVALIDREF(riCharlie); (* becomes FALSE, because riCharlie is set to 0 *)
In compiler version 3.5.7.40 and higher, the implicit monitoring function “CheckPointer” acts on variables of type REFERENCE TO
in the same way as for pointer variables.