-

SIZEOF

Type Function
Description Determines the number of bytes reserved for the input variable in the controller memory and outputs it as UDINT value. The function is especially useful for determining the size of user-defined ARRAYs, STRUCTs or STRINGs.

If, for example, an array consists of DINT elements, each element would occupy 4 bytes. The total number of bytes reserved for the input variable would be calculated as follows:

    Number of array elements x Number of bytes occupied by an element

In case of DINT elements, the number of array elements would be multiplied by 4 (see also the example below).
Notes The size of the same ARRAY, STRUCT or STRING applied to the input differs depending on the used controller type.
Parameters Input

IN

Output

OUT
Example Example in ST
Specialities for STRUCTs In the controller memory, a STRUCT is stored as follows:

  • The start address of each individual STRUCT element is always divisible by its size. In the example below, the MyDINT variable does not start at address 14 (although this would be the next free location) but at address 16, because 16 is divisible by the DINT size 4 (bytes).

    And:

  • The size of the entire STRUCT is always divisible by the size of the biggest contained generic data type (LINT = 8 bytes in the example below). This ensures that the start address of the entire STRUCT is also divisible by the STRUCT size.
This means, depending on the composition of the STRUCT, the SIZEOF function may deliver a bigger value than you would get when simply adding the sizes of the contained elements.

Example