Troubleshooting
Why stored PLC pointers break after an online change
Short answer
An online change can relocate the variables a program already stored addresses for, and the stored pointer keeps the old address, so the next dereference touches the wrong memory. Re-evaluate every pointer with ADR after the change and before the next dereference, or avoid the online change and run a full download where pointers are stored permanently.
On this page
- What happens to a stored PLC pointer during an online change?
- Why does a stale pointer dereference raise no exception?
- What does the ADR warning about online change say?
- How do you find the pointer binding an online change broke?
- How do you repair pointers after an online change?
- How do you write pointers that survive online changes?
- When should you download instead of changing the program online?
- Questions asked
A stored PLC pointer breaks after an online change because the change can relocate the data while the pointer keeps the old address: the pointer variable is untouched, its value is simply no longer where its target lives. The next dereference then reads or writes a different variable, usually without any exception. The documented fix is to rebuild the binding: after the change and before the first dereference, re-evaluate the address with ADR, refresh member pointers and every stored copy, and verify against a freshly evaluated address. Where pointers are stored permanently as bindings between structures and no gated rebuild exists, skip the online change and run a full download at a planned stop. The sections below work through the mechanism, the manufacturer warning, the diagnosis, the repair and the decision for each case, using TwinCAT 2.10 and CoDeSys 2.3 as the reference pair.
What happens to a stored PLC pointer during an online change? #
An online change can move the variables your program already addressed, and a stored pointer keeps the old numeric address, so the next dereference lands where the target used to be — in the worked example below, 288 bytes (16#120) away from it.
The pointer itself does not break: its value survives the change untouched. What breaks is the relationship. IEC 61131-3 defines ADR as the operator that delivers the address of a variable at the moment it executes, and a POINTER TO declaration as a variable that holds such an address. Nothing in that pair ties the stored number to the variable it came from, and the runtime keeps no live link, so a relocation leaves the number pointing at the old slot.
The addresses in this example are invented to show the mechanism; the documented part is that an online change can move statically declared data. A global array starts at 16#00324A10 and a one-time initialization stores its address:
arBuffer : ARRAY[1..64] OF DWORD; // illustrative variable
pBuffer : POINTER TO DWORD; // illustrative pointer
pBuffer := ADR(arBuffer); // init run: pBuffer holds 16#00324A10
An online change now adds declarations totalling 288 bytes ahead of the array, and the runtime relocates it to 16#00324B30 while pBuffer still holds 16#00324A10. The arithmetic: 16#4A10 + 16#120 = 16#4B30, and 16#120 = 256 + 32 = 288 bytes, so the stored address sits 288 bytes below the array's new start. A write through pBuffer^ then lands in whatever variable now occupies that slot.
Whether the address moves at all depends on where the new declarations land: the documentation says an online change can change addresses, not that it always does. Nothing ahead of the target, and it may stay put — but no guarantee comes with that.
Why does a stale pointer dereference raise no exception? #
The old address usually still points into allocated memory, so the access succeeds numerically while it corrupts a different variable — you see plausible values, wrong outputs or an intermittent fault hours later, not a clean runtime error at the dereference.
The relocation does not free the memory region: the old slot stays inside allocated data memory and now holds a different variable. A read through the stale pointer returns plausible garbage; a write silently corrupts an unrelated variable. An exception comes only when the stale address leaves the allocated region entirely, which a shift of a few hundred bytes rarely does. That is why the field symptom is an intermittent wrong value long after the download, not a crash at the moment of the change.
What does the ADR warning about online change say? #
Beckhoff's help for the ADR operator warns that an online change can change the data on certain addresses and must be regarded when using pointers on addresses — a warning, not an automatic fix.
Quoted in full, the warning reads: "After an Online Change there might be changes concerning the data on certain addresses." The same help documents ADR as the operator that assigns the address of an object to a pointer, written ADR(nVar1): evaluation happens where the operator executes, which is exactly the property the repair below relies on.
TwinCAT 2.10's PLC engineering environment descends from CoDeSys 2.3, and that generation of help carries the warning with no statement that pointers are corrected for you. Later-generation documentation for pointers and references describes the opposite behavior for its generation: during an online change the values of all PLC pointers are automatically updated so that each pointer still refers to the same variable or object. Even that generation notes that an online change can change the addresses of statically declared variables and objects and that an address can be queried again using ADR. The dependable rule is the same in every generation: a stored address is invalid until re-evaluated.
If you have met the SCADA version of this fault — why PLC symbol changes break SCADA tags in OFS — the shape is identical: a reference stored on one side of a change, invalidated by the change, still perfectly formed and pointing at nothing.
How do you find the pointer binding an online change broke? #
List every place the program stores an ADR result, then read the stored pointer and the freshly evaluated address of its target at the same execution point — a mismatch proves the binding is stale, and a match does not yet prove the access is right.
- Search the project for every ADR call and every POINTER TO declaration, and sort them into addresses evaluated each cycle and addresses assigned once.
- Trace each stored pointer to every dereference, including accesses inside called functions and function blocks and any copy stored in another structure.
- At one controlled execution point — a breakpoint or a single task cycle — record the stored pointer value and evaluate ADR on the intended target.
- A mismatch proves the binding is stale: rebuild it before the next dereference, using the repair below.
- A match does not close the case: check the target's type and layout too, because a structure that gained a member shifts every member-pointer offset while the base address stays equal.
- Refresh dependencies in order: pointers to members and addresses computed from a base must come from the freshly evaluated base, never from another pointer's old value.
TwinCAT's help documents a Go to reference command for online mode that jumps from a pointer to the variable it references; after a change it is a fast way to see where each binding actually lands. If several tasks consume the same pointers, check execution order too: rebuilding an address in one task does not make an earlier access in another task safe.
How do you repair pointers after an online change? #
Rebuild every stored binding after the online change and before the first dereference: stop the pointer-consuming logic, re-run ADR against each current target, rebuild member and copied pointers from the fresh base, then release the consumers.
- Identify every consumer of the affected pointers, direct and reached through linked structures.
- Gate the dereferences behind one flag so no pointer-dependent operation runs during the rebuild, and account for what pausing them does to the process.
- Apply the online change through the engineering tool's documented workflow.
- Re-evaluate every stored address with ADR once the new data layout is in place, and rebuild member pointers and stored copies from the fresh bases.
- Verify each binding: the stored value equals a freshly evaluated ADR of the target, the type matches, and every access stays inside the object's boundaries.
- Release the gate only after every binding passes, and run the rebuild again after any later change.
The fence shows one rebuilt binding and the test that proves it; names and the hex pattern are illustrative, while POINTER TO and ADR are the documented IEC 61131-3 pointer type and address operator:
pBuffer : POINTER TO DWORD; // illustrative pointer
arBuffer : ARRAY[1..64] OF DWORD; // illustrative array
xRebind : BOOL; // pulsed once after the online change
xValid : BOOL; // gates every pointer consumer
IF xRebind AND NOT xValid THEN
pBuffer := ADR(arBuffer); // fresh evaluation, not a stored copy
arBuffer[1] := 16#DEADBEEF; // known pattern written directly
IF pBuffer^ = 16#DEADBEEF THEN
xValid := TRUE; // dereference proven to reach the array
END_IF
xRebind := FALSE;
END_IF
If pBuffer still held the pre-change address from the worked example, the comparison fails and xValid stays FALSE, holding every consumer off until the binding is genuinely rebuilt.
One safety note: if a dereference feeds an interlock, a drive setpoint or anything your risk assessment treats as safety-related, keep the writes gated until that check passes and treat the ungated state as a machine fault.
How do you write pointers that survive online changes? #
Do not store an ADR result across an online change: evaluate the address immediately before the dereference, or rebuild all bindings in one defined place at startup, and keep any address that must persist out of the online-change path entirely.
- Evaluate and dereference in the same cycle: ADR immediately before the access leaves no stored address for a change to strand.
- Where you cannot avoid storing, store an index or a symbolic key and resolve it with ADR at each use — the stored thing is a name, not an address.
- Give one rebuild routine ownership of every binding in the program and call it at startup and after every change, so no binding depends on initialization order.
- Keep mutually linked structures out of online-change edits: a layout change there relocates every node and every stored link between them.
- Treat each change individually: one online change that leaves addresses untouched proves nothing about the next.
When should you download instead of changing the program online? #
When pointers are stored permanently as structural bindings between data structures and the program cannot gate and rebuild them deterministically at runtime, do not send an online change: plan a stop, a full download and a restart with explicit pointer initialization instead.
- Addresses evaluated with ADR at each use: use the online change freely, because nothing stored exists to strand.
- Stored addresses with a gated rebuild path: the online change is usable, but only with the rebuild run to a verified pass before consumers release, checked per change.
- Stored structural bindings across function blocks with no gated rebuild: no online change — a planned stop, a full download and a restart with explicit pointer initialization.
On the 2.10 and 2.3 generation the help gives you the warning and nothing more, so both the rebuild and the decision stay yours.
Questions asked
Do pointers break after every online change?
No. Only a change that moves the affected data strands a stored address, and an edit to pure logic can leave every address untouched. The runtime does not give you a list of what moved, so the dependable practice is to re-evaluate every stored pointer with ADR after any online change, however small the edit looked.
Where do stale copies of a pointer usually hide?
In function block instance data, in parameter or recipe structures that captured an address once, in linked list and ring buffer nodes that point at each other, and in any copy passed to another program organization unit. Refreshing the original variable updates none of the copies, so every stored address needs its own fresh ADR evaluation, rebuilt from the current objects rather than from another pointer's value.
Does a zero pointer value prove a binding is broken, and a nonzero value prove it is good?
Neither direction works the way you would hope. A zero value reliably means there is no binding at all, but a stale nonzero address usually still lands inside allocated memory, so it reads and writes without an exception. The dependable check compares the stored value against a freshly evaluated ADR of the intended target, read within one task cycle so nothing relocates between the two accesses.
Is this a TwinCAT quirk or standard IEC 61131-3 behavior?
The language standard defines the pointer type and the ADR address operator, but it leaves online change to the runtime, so the behavior you get is whatever the vendor documents for that generation: a warning on the older line, automatic pointer updates described on the newer one. Treat re-evaluation with ADR before each dereference as the rule that holds everywhere.