SIZEOF block

Short summary

Name

SIZEOF

→POU type

→function

Category

IEC-block, MemoryEnh

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/add.svg not defined in IEC-standard

Graphical interface

images/download/thumbnails/414781845/SIZEOF-version-1-modificationdate-1535027074385-api-v2.png

Available since

version 1.34.0 (for logi.CAD 3)

Functionality

The block returns the memory (in bytes) required by the element connected to input IN (e.g. a →variable or a →literal).

Special cases (see under "Example for usage within ST-editor" ) :

  • The call of the SIZEOF block without connected element (i.e. without parameter list) returns value 1. Reason: Here the data type BOOL is used.

  • The length of the STRING buffer is returned in case of STRING elements with a length. The length of the STRING buffer is determined by the declaration.
    STRING elements with a length are STRING variables declared by you; see "Declaration of STRING variables (incl. access)".

  • The length of the STRING buffer is also returned in case of STRING elements without a length. However, the length of the STRING buffer is determined by the resulting value.
    STRING elements without a user-defined length are resulting, if you are using STRING functions or →character string literals.

Inputs, return value


Identifier

→Data type

Description

Inputs:

IN

REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, STRING, CHAR, DATE_AND_TIME, DATE, TIME_OF_DAY, a →user-defined data type or a →reference
Restriction: In case of →array data types, only one-dimensional arrays are allowed.

input value

Return value:

UDINT


Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Example for usage within ST-editor

PROGRAM Test
VAR
result : ARRAY[1..12] OF UDINT;
RealVar : REAL := 1.234E6;
StringVar : STRING[10] := 'abcdef';
RefVar : REF_TO STRING[10] := REF(StringVar);
StructVar : MyStruct;
ArrayVar : MyArray;
FB1 : MyFB;
END_VAR
result[1] := SIZEOF(IN := BOOL#TRUE); (* The variable 'result[1]' evaluates to '1'. *)
result[2] := SIZEOF(IN := INT#500); (* The variable 'result[2]' evaluates to '2'. *)
result[3] := SIZEOF(IN := RealVar); (* The variable 'result[3]' evaluates to '4'. *)
result[4] := SIZEOF(IN := StringVar); (* The variable 'result[4]' evaluates to '11'. *)
result[5] := SIZEOF(IN := CONCAT(StringVar,StringVar)); (* The variable 'result[5]' evaluates to '13'. *)
result[6] := SIZEOF(IN := STRING#'abcdef'); (* The variable 'result[6]' evaluates to '7'. *)
result[7] := SIZEOF(); (* The variable 'result[7]' evaluates to '1'. *)
result[8] := SIZEOF(IN := RefVar); (* The variable 'result[8]' evaluates to '4'. *)
result[9] := SIZEOF(IN := RefVar^); (* The variable 'result[9]' evaluates to '11'. *)
result[10] := SIZEOF(IN := StructVar); (* The variable 'result[10]' evaluates to '8' - due to alignment rules. *)
result[11] := SIZEOF(IN := ArrayVar); (* The variable 'result[11]' evaluates to '20'. *)
result[12] := SIZEOF(IN := FB1); (* The variable 'result[12]' evaluates to '8' - due to alignment rules and ENO variable. *)
END_PROGRAM
TYPE
MyStruct : STRUCT
Elem1 : BOOL := TRUE;
Elem2 : INT := 500;
Elem3 : REAL := 1.234E6;
END_STRUCT;
MyArray : ARRAY [1..10] OF INT;
END_TYPE
FUNCTION_BLOCK MyFB
VAR_INPUT
I1 : BOOL;
I2 : INT;
END_VAR
VAR_OUTPUT
O1 : BOOL;
O2 : INT;
END_VAR
END_FUNCTION_BLOCK

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.