ADR

Returns the address of a variable as a typed pointer.

IEC 61131-3

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

Support

Supported (requires --allow-adr)

Signatures

#

Input (IN)

Return Type

Support

1

ANY (a named variable)

POINTER TO type of input

Supported

Description

ADR returns the address of a variable, typically for assignment to a POINTER TO variable that is later dereferenced with ^. It is not part of the IEC 61131-3 standard but is a Beckhoff TwinCAT / CODESYS extension:

pNumber := ADR(iNumber1);   (* point at iNumber1 *)
iNumber2 := pNumber^;       (* read through the pointer *)
pNumber^ := 7;              (* write through the pointer *)

In TwinCAT and CODESYS, ADR yields a raw machine address (PVOID) that those environments also allow assigning to integer types such as DWORD or LWORD. IronPLC variables do not have byte addresses, so ADR(x) instead has the typed result POINTER TO type of x and is type-checked against the destination pointer’s target type. This is stricter than TwinCAT and CODESYS — see Restrictions below for the address-manipulation patterns that do not carry over.

Enabling

ADR is a language extension and must be explicitly enabled:

ironplcc check --allow-pointer-to --allow-adr main.st

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

Example

p := ADR(counter);
value := p^;     (* value = 42 *)
p^ := 99;        (* counter = 99 *)

Restrictions

  • The operand must be a simple named variable. Addresses of sub-objects — array elements (ADR(arr[i])), structure fields (ADR(s.field)) — and of literals or call results are rejected.

  • The operand must not be a stack-allocated variable (VAR_TEMP, function parameters), which would produce a dangling pointer.

  • The result must be assigned to a pointer or reference variable. Assigning an address to an integer variable (DWORD/LWORD), pointer arithmetic, and byte-level tricks such as MEMCPY do not carry over from TwinCAT / CODESYS.

External References

See Also