POINTER TO is type-unsafe
Variables defined as a POINTER TO
data-type are considered type-unsafe in the sense that no validation will
trigger when assigning incorrect types. For example the following code, while incorrect, will not return any
diagnostics when compiling:
VAR
stringVar : STRING;
unsafePtrA : POINTER TO DINT := ADR(stringVar);
unsafePtrB : POINTER TO DINT := REF(stringVar);
END_VAR
For best practices, consider using REF_TO
instead of POINTER TO
, which is a type-safe alternative and should catch
type-mismatches early on