__ISVALIDREF

Returns whether a REFERENCE TO variable is currently bound to a valid target.

IEC 61131-3

Not part of the standard (Beckhoff TwinCAT / CODESYS extension)

Support

Supported (requires --allow-reference-to)

Signatures

#

Input (IN)

Return Type

Support

1

REFERENCE TO ANY

BOOL

Supported

Description

__ISVALIDREF reports whether a REFERENCE TO variable currently refers to a valid target. It returns TRUE once the reference has been bound with REF= and FALSE while it is unbound (null). It is not part of the IEC 61131-3 standard but is a Beckhoff TwinCAT / CODESYS extension, typically used to guard a dereference so that reading or writing through an unbound reference is avoided.

The argument is the reference itself — __ISVALIDREF inspects the binding, so (unlike an ordinary read of a REFERENCE TO variable) the argument is not automatically dereferenced. IronPLC lowers __ISVALIDREF(r) to the equivalent comparison r <> NULL.

__ISVALIDREF is recognized as a builtin only when --allow-reference-to is enabled. Without that flag it is treated as an ordinary (undeclared) function name.

Enabling

__ISVALIDREF is a vendor extension and must be explicitly enabled:

ironplcc check --allow-reference-to main.st

Pass the --allow-reference-to flag to enable it, or select a dialect that includes it. See Enabling Dialects and Features for the dialects and flags reference.

Example

valid := __ISVALIDREF(r);   (* valid = FALSE, r is unbound *)
r REF= x;
valid := __ISVALIDREF(r);   (* valid = TRUE, r is now bound *)

See Also