Explainer
Why a TwinCAT struct is a type, not a data block
Short answer
A TwinCAT STRUCT declaration defines a type and reserves no memory; storage appears when you declare an instance such as My_table: TABLE_1, which the compiler addresses symbolically, so ordinary variables cannot overwrite each other. Overlap becomes possible only with explicit AT locations such as %MW0, and the PLC Control option Check for overlapping addresses turns a clash into a compiler error. To group values like a Siemens data block, define the type and declare a global instance.

On this page
In TwinCAT, a STRUCT declaration is a type: it fixes member names and data types and reserves no memory at all. Storage exists only when you declare an instance such as My_table: TABLE_1, and the compiler then addresses that instance symbolically, giving every ordinary variable its own space, so one symbolic variable cannot overwrite another. The exception is an explicit location such as sHMIOperatorID AT %MW0: WORD, where two declarations pinned into the same %M bytes really do share memory and by default nothing flags the clash. Grouping values the way a Siemens data block does is therefore entirely possible: define the type, declare instances, and pin absolute addresses only where a device manual names the register.
A type is a layout; an instance is the storage #
A type declaration answers one question: what will the value look like? Take a four-station recipe table:
TYPE TABLE_1 :
STRUCT
ON_OFF : ARRAY [1..4] OF BOOL;
Set_pieces : ARRAY [1..4] OF UINT;
Act_pieces : ARRAY [1..4] OF UINT;
END_STRUCT
END_TYPE
After this there is still nothing to write to and no bytes to inspect: TABLE_1 is a drawing, not a variable. The storage appears with the instance:
VAR
My_table : TABLE_1;
END_VAR
My_table is the variable the program uses, and My_table.Set_pieces[1] names one element of it. Where the VAR block sits decides visibility: inside a program it stays local, while a global variable list lets every POU reach it. This is the same distinction that separates a function block declaration from its instance, the type-versus-call test covered in function or function block: the two tests that decide. So the first move on any suspicion that a struct overwrote something is to find the instance declaration: no instance, no storage, nothing to overwrite.
Symbolic addressing is the default #
For ordinary variables TwinCAT handles the addressing itself: you declare names and the toolchain places each variable automatically, in what the documentation calls flexible and optimized addressing. Because the compiler owns that placement, every symbolic variable receives its own storage, and allocation cannot make two of them collide. Absolute locations exist for the cases where a partner demands a fixed interface, and the pattern is a declaration such as:
sHMIOperatorID AT %MW0: WORD;
That pins one word to offset zero of the %M memory area, where an external tool reads it by address. Two consequences follow. First, the rule stated in the TwinCAT introduction: do not use direct addressing for variables the system already allocates, an I/O point linked by name being the everyday example; give those their symbolic link and let the system place them. Second, every AT declaration you keep is a map you maintain, and the next section shows what a mistake on that map looks like.
How two variables end up sharing memory #
Beckhoff's documentation on addresses gives the minimal collision: a WORD variable placed at W0 and a BOOL placed at B1 overlap. The word occupies bytes 0 and 1, and the bit lives inside byte 1, so writing the word rewrites the bit and setting the bit moves the word's value in multiples of 256, the classic fingerprint of a high-byte bit being toggled behind your back. The documentation singles out byte addressing mode as a place to watch for exactly this, and the compiler reports none of it by default.
The documented guard lives in TwinCAT PLC Control: the Settings dialog of the PLC configuration carries the option 'Check for overlapping addresses', and with that option active a detected overlap is reported as a compiler error. Switch it on and leave it on for the life of the project. The audit behind it is mechanical and worth knowing anyway: list every declaration containing AT %, sort by area and then by offset, and compare each variable's byte span, two bytes for a WORD and four for a DWORD, against its neighbours. A pinned map earns that audit after every change to it.
Sizing the member data of one TABLE_1 instance for four stations #
The worked case is the recipe table above, one instance, four stations.
Inputs #
- ON_OFF: 4 elements of BOOL; the count comes from the declaration, and BOOL is 1 bit wide under IEC 61131-3.
- Set_pieces: 4 elements of UINT, 16 bits wide under the same standard.
- Act_pieces: 4 elements of UINT, same width.
Rule #
The member data of an instance is the sum of its members' sizes. The compiler may insert alignment padding between members, so treat the sum as a floor and read the final size from the built project's symbol and address listing.
Arithmetic #
- ON_OFF: 4 × 1 bit = 4 bits
- Set_pieces: 4 × 16 bits = 64 bits
- Act_pieces: 4 × 16 bits = 64 bits
- Sum: 4 + 64 + 64 = 132 bits
- 132 bits ÷ 8 = 16.5 bytes, which is 17 bytes rounded up to whole bytes, before any padding
Result and decision #
One instance holds 17 bytes of member data plus whatever padding the compiler adds. A fifth station would cost 1 + 16 + 16 = 33 bits per station, so even a hundred-station version of the same three arrays totals 100 × 33 bits = 3300 bits, about 413 bytes, a size that never influences controller selection. The decision follows: declare the table symbolically and spend zero absolute addresses on it, and pin a member with AT only when a device manual documents that register for an external reader, with the overlap check guarding the pinned span.
Grouping values like a Siemens data block #
The habit worth copying from a Siemens DB is one named block holding a machine's recipe values, and it maps directly. Define the type once among the project's data types, as TABLE_1 above. Declare one instance in a global variable list, which gives every POU the same project-wide view a global data block gives. Reference members by path, with My_table.Act_pieces[2] dropping straight into a comparison or a move, and initialize and monitor the group in that one place. What you give up is the DB number and offset access from outside; what you keep is the single named home for related values, which is the part that made DBs worth imitating. When the group must repeat per order or per station, the next step is an array of the type, and a structured text array of struct declaration and setup shows that pattern. Keep such arrays symbolic as well: clients that browse TwinCAT symbols read member paths with no address map to maintain.
When values change with no AT declaration in sight #
If a member of My_table changes when no code should touch it, search the project for the string AT %; the search takes a minute. An empty result acquits the memory map: symbolic allocation cannot produce the corruption, so stop suspecting the struct's layout and trace writers instead. Put the instance name into the cross-reference, list every write access, and the extra writer is in that list, whether it is a second task or rung writing the same instance, an out-of-range array index where bounds checking is off in the build, or a communications client writing symbols it should only read. Each of those is a code fault with a code fix, and none of them is a struct overwriting a neighbour.
Questions asked
Is VAR_CONF a memory area that can overwrite other variables?
VAR_CONF, as written, is not a standard declaration keyword, and no declaration keyword reserves memory by itself. What allocates storage is a variable declared inside a VAR block, whatever that block is called. If the name comes from a declaration in your project, open it and look for a variable of the struct type: with no instance there is no storage and nothing to overwrite. Only an explicit AT location can make two declarations share memory.
Where do I see the address TwinCAT actually assigned to an instance?
Build the project and open the generated symbol and address information: the compiler publishes each variable's area, offset and size there, and TwinCAT ADS clients can browse the same type system, which exposes a struct's members as a read-only collection. Read the listing rather than computing offsets by hand, because alignment padding makes the bit arithmetic a floor, not the final layout.
Should a new TwinCAT project use any absolute addresses at all?
Only where a documented fixed interface demands one, for example a word that an external tool reads at a set location. Every other variable stays symbolic: a recompile can move symbolic variables without breaking anything, while a pinned map must be re-audited after each such change. A healthy new project has exactly as many AT declarations as there are documented external registers, and no more.


