VAR_GENERIC CONSTANT in TwinCAT: The Nuances Nobody Writes About
A summary of experiments with generic arrays in TwinCAT/CoDeSys, clarifying compiler support for various use cases.
I ran a series of experiments and here are the answers to questions that are not obvious. This is about a generic array like on the screenshot below.
1. Can a generic array be used in FB_Init?
✗ No — the compiler does not support this.
2. Can a generic array be specified as a method parameter?
✓ Yes — it works.
3. Can a property of type generic array be created?
✓ Yes — possible.
4. Can UPPER_BOUND be called with a generic array?
✗ No — currently there are bugs with this.
5. Can a literal (like [1, 2, 3, 4]) be used as a generic array value, for example in a method parameter?
✗ No — not supported.
6. Can a generic array be passed as a variable‑length array (ARRAY [*] OF)?
✓ Yes — it works.
7. Can a generic constant be defined such that the generic array contains no elements?
✓ Yes — possible.

#TwinCAT #CoDeSys #StructuredText