SIZEOF block
Short summary
Name |
SIZEOF |
→POU type |
|
Category |
|
Conform to →IEC-standard |
not defined in IEC-standard |
Graphical interface |
|
Available since |
|
Functionality
The block returns the memory (in bytes) required by the element connected to the input IN (e.g. a
→variable
or a →literal). In this case, the required memory size of the data type of the input IN is determined.
It is possible to configure the required memory of data types based on compiler or platform settings.
Special cases (see under "Example for usage within ST-editor" ) :
If a BOOL element is connected, the returned memory depends on the platform used for the →PLC. Usually, the value 1 is returned.
The call of the SIZEOF block without a connected element (i.e. without a parameter list) usually returns value 1. Reason: Here the data type BOOL is used.
If a →reference is connected, the returned memory depends on the architecture of the created application (32- or 64-bit).
If an →array element with an index ix connected, the base type of the array element is used (for the returned memory) and the specified index itself is not checked (e.g. whether the index exists).
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 |
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, a →function block or a →reference
Further restriction: In the case of function blocks, no function blocks with a →generic data type are allowed. As a result of this restriction, you cannot use the following blocks as input of the current block: LIMITER_O, LIMITER_U, FORCEMRK, MAX_HOLD, MIN_HOLD, and
→vendor-function blocks that have been
declared with a generic data type. |
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:
"Blocks for safe logic" whether this block is supported for developing safety-relevant applications.
"Highlighting safe logic in the FBD-editor" for the effects when using the block as a block for safe logic .
Example for usage within ST-editor
The calculated values are evaluated by using the Assert block .
FUNCTION_BLOCK ExampleSizeOf
VAR
result : ARRAY[
1
..
12
] OF UDINT;
RealVar : REAL :=
1
.234E6;
StringVar : STRING[
10
] :=
'abcdef'
;
RefVar : REF_TO STRING[
10
] := REF(StringVar);
StructVar : ExampleSizeOfStruct;
ArrayVar : ExampleSizeOfArray;
FB1 : ExampleSizeOfFB;
END_VAR
result[
1
] := SIZEOF(IN := BOOL#TRUE);
result[
2
] := SIZEOF(IN := INT#
500
);
result[
3
] := SIZEOF(IN := RealVar);
result[
4
] := SIZEOF(IN := StringVar);
result[
5
] := SIZEOF(IN := CONCAT(StringVar,StringVar));
result[
6
] := SIZEOF(IN := STRING#
'abcdef'
);
result[
7
] := SIZEOF();
result[
8
] := SIZEOF(IN := RefVar);
result[
9
] := SIZEOF(IN := RefVar^);
result[
10
] := SIZEOF(IN := StructVar);
result[
11
] := SIZEOF(IN := ArrayVar);
result[
12
] := SIZEOF(IN := FB1);
(* The following statements are
true
,
if
the application is loaded onto the built-in PLC. *)
ASSERT(result[
1
] =
1
); (* For a PLC based on the vxWorks platform,
'result[1]'
might evaluate to
'4'
. *)
ASSERT(result[
2
] =
2
);
ASSERT(result[
3
] =
4
);
ASSERT(result[
4
] =
11
);
ASSERT(result[
5
] =
13
);
ASSERT(result[
6
] =
7
);
ASSERT(result[
7
] =
1
); (* For a PLC based on the vxWorks platform,
'result[7]'
might evaluate to
'4'
. *)
ASSERT(result[
8
] =
4
); (* This statement is
true
for
a
32
-bit PLC. For the
64
-bit PLC,
'result[8]'
evaluates to
'8'
. *)
ASSERT(result[
9
] =
11
);
ASSERT(result[
10
] =
8
); (* The variable
'result[10]'
evaluates to
'8'
- due to alignment rules. *)
(* For a PLC based on the vxWorks platform,
'result[10]'
might evaluate to
'10'
. *)
ASSERT(result[
11
] =
20
);
ASSERT(result[
12
] =
8
); (* The variable
'result[12]'
evaluates to
'8'
- due to alignment rules and ENO variable. *)
(* For a PLC based on the vxWorks platform,
'result[12]'
might evaluate to
'16'
. *)
END_FUNCTION_BLOCK
TYPE
ExampleSizeOfStruct : STRUCT
Elem1 : BOOL := TRUE;
Elem2 : INT :=
500
;
Elem3 : REAL :=
1
.234E6;
END_STRUCT;
ExampleSizeOfArray : ARRAY [
1
..
10
] OF INT;
END_TYPE
FUNCTION_BLOCK ExampleSizeOfFB
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.