Incompatible POINTER TO types in class/function block hierarchy
This error occurs when a POINTER TO assignment involves two class or function block types
that are not in a valid inheritance relationship. Only upcasts (child to parent) and same-type
assignments are allowed.
POINTER TO is the recommended mechanism for polymorphism per IEC 61131-3. When working with
class or function block hierarchies, the compiler checks that pointer assignments respect the
EXTENDS chain: the right-hand side must be the same type as, or a subtype of, the left-hand
side’s pointee type.
Invalid examples
Unrelated types
FUNCTION_BLOCK FbA
END_FUNCTION_BLOCK
FUNCTION_BLOCK FbX
END_FUNCTION_BLOCK
FUNCTION main
VAR
instance : FbX;
ptr : POINTER TO FbA;
END_VAR
ptr := ADR(instance); // Error: FbX is not a subtype of FbA
END_FUNCTION
Downcast (parent assigned to child pointer)
FUNCTION_BLOCK FbA
END_FUNCTION_BLOCK
FUNCTION_BLOCK FbB EXTENDS FbA
END_FUNCTION_BLOCK
FUNCTION main
VAR
instance : FbA;
ptr : POINTER TO FbB;
END_VAR
ptr := ADR(instance); // Error: FbA is not a subtype of FbB
END_FUNCTION
Sibling types
FUNCTION_BLOCK FbA
END_FUNCTION_BLOCK
FUNCTION_BLOCK FbB EXTENDS FbA
END_FUNCTION_BLOCK
FUNCTION_BLOCK FbC EXTENDS FbA
END_FUNCTION_BLOCK
FUNCTION main
VAR
instance : FbC;
ptr : POINTER TO FbB;
END_VAR
ptr := ADR(instance); // Error: FbC is not a subtype of FbB
END_FUNCTION
Valid examples
Same type
FUNCTION_BLOCK FbA
END_FUNCTION_BLOCK
FUNCTION main
VAR
instance : FbA;
ptr : POINTER TO FbA;
END_VAR
ptr := ADR(instance); // OK
END_FUNCTION
Upcast (child assigned to parent pointer)
FUNCTION_BLOCK FbA
END_FUNCTION_BLOCK
FUNCTION_BLOCK FbB EXTENDS FbA
END_FUNCTION_BLOCK
FUNCTION main
VAR
instanceB : FbB;
ptrA : POINTER TO FbA;
ptrB : POINTER TO FbB;
END_VAR
ptrA := ADR(instanceB); // OK: FbB extends FbA
ptrA := ptrB; // OK: same relationship
END_FUNCTION