Data types

Data types

Every IEC 61131-3 variable has a type. The type controls storage size, value range, allowed operations, and which conversion calls are needed when the value is used somewhere expecting a different type.

Sub-pages

  • Elementary typesBOOL, BYTE, INT, REAL, TIME, STRING and their cousins. The building blocks.
  • Generic types ANY, ANY_NUM, ANY_INT, ANY_BIT, ANY_REAL appear in standard-library function signatures (e.g. ABS(IN: ANY_NUM): ANY_NUM). They cannot be used in user variable declarations. (Stub.)
  • Derived types — STRUCT, ARRAY, enumerations, type-safe aliases (TYPE … : … END_TYPE). (Stub.)

Type-strict philosophy

IEC 61131-3 is strongly typed and matiec is among the strictest implementations. Two key consequences:

  1. No implicit conversion across families. INT + REAL is a type error; you write INT_TO_REAL(i) + r. INT vs UINT is a comparison error; you write i = UINT_TO_INT(u).
  2. No “truthy” coercion. IF iCount THEN … is illegal — the condition must be an explicit BOOL: IF iCount > 0 THEN.

These rules trade convenience at the call site for predictability at run-time. PLC code outlives its writer and runs unattended; the type-strictness pays back when the next maintainer reads the code.

Quick reference: type widths

TypeWidthRange / values
BOOL1 bitFALSE, TRUE
BYTE8 bitsbit string, 0..255 unsigned
WORD16 bitsbit string, 0..65535 unsigned
DWORD32 bitsbit string, 0..2³²-1 unsigned
LWORD64 bitsbit string, 0..2⁶⁴-1 unsigned
SINT8 bits signed-128..127
INT16 bits signed-32 768..32 767
DINT32 bits signed-2³¹..2³¹-1
LINT64 bits signed-2⁶³..2⁶³-1
USINT8 bits unsigned0..255
UINT16 bits unsigned0..65 535
UDINT32 bits unsigned0..2³²-1
ULINT64 bits unsigned0..2⁶⁴-1
REAL32 bits IEEE-754~7 significant decimal digits
LREAL64 bits IEEE-754~15 significant decimal digits
TIMEimpl-definedduration, e.g. T#1h30m
DATEimpl-definedcalendar date, e.g. D#2026-05-14
TIME_OF_DAY / TODimpl-definedwall-clock time, e.g. TOD#14:30:00
DATE_AND_TIME / DTimpl-definedtimestamp, DT#2026-05-14-14:30:00
STRINGimpl-definedvariable-length character string

IEC reference

IEC 61131-3 third edition (2013), clause 6.4 — “Data types”.

ForgeIEC notes

  • The ForgeIEC pool stores every variable’s IEC type as a string field. The MCP tool project.list_pool_variables returns it in the iec_type field of each entry.
  • The ForgeIEC ST code generator emits matiec-compatible IEC types verbatim — no remapping. A variable declared INT in the editor is INT to matiec.