SIZEOF

Returns the size in bytes of a variable or type.

IEC 61131-3

Not part of the standard (language extension)

Support

Supported (requires --allow-sizeof)

Signatures

#

Input (IN)

Return Type

Support

1

ANY

ANY_INT

Supported

Description

SIZEOF returns the size in bytes of the argument’s type as a compile-time constant. It is not part of the IEC 61131-3 standard but is a widely supported language extension available in CODESYS, TwinCAT/Beckhoff, and RuSTy. It is commonly used in buffer management functions that work with REF_TO pointers, such as those in the OSCAT library.

For elementary types, SIZEOF returns the number of bytes the type occupies:

  • BOOL → 1

  • INT → 2

  • DINT / DWORD / REAL → 4

  • LINT / LREAL → 8

For arrays, SIZEOF returns the total number of bytes occupied by all elements (element count × element size).

Enabling

SIZEOF is a language extension and must be explicitly enabled:

ironplcc check --allow-sizeof main.st

Pass the --allow-sizeof flag to enable it, or select a dialect that includes it. See Enabling Dialects and Features for the dialects and flags reference.

Example

s := SIZEOF(x);     (* s = 2 *)
s := SIZEOF(arr);   (* s = 20 *)

See Also