Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Member access on a non-auto-deref pointer base

Member access (base.member) requires base to be a struct, function-block, or class instance — not a pointer to one. The compiler will not implicitly dereference pointers when they appear on the left of a . (auto-dereferencing applies only to REFERENCE TO / alias pointers).

This rule covers three cases that share the same underlying shape — the value of base is a pointer, not the pointee:

  1. THIS is POINTER TO <enclosing FUNCTION_BLOCK>. Use THIS^.member.
  2. SUPER is POINTER TO <parent POU> (before dereferencing). Use SUPER^.member.
  3. A user-declared POINTER TO ... variable. Use <pointer>^.member.

Example of invalid use

FUNCTION_BLOCK fb
    VAR
        a : DINT;
    END_VAR
END_FUNCTION_BLOCK

FUNCTION_BLOCK other
    VAR
        p_fb : POINTER TO fb;
    END_VAR
    METHOD m : DINT
        p_fb.a := 1;   // Error: Cannot access `a` on `POINTER TO fb`
        THIS.b := 2;   // Error: Cannot access `b` on `POINTER TO other` (THIS is a pointer)
    END_METHOD
END_FUNCTION_BLOCK

Example of valid use

FUNCTION_BLOCK other
    VAR
        p_fb : POINTER TO fb;
        b    : DINT;
    END_VAR
    METHOD m : DINT
        p_fb^.a := 1;   // Dereference the pointer first
        THIS^.b := 2;   // Dereference THIS first
    END_METHOD
END_FUNCTION_BLOCK