# sizeof

This function returns the declared number of elements of a record, record of, set, set of type or the actual number of elements of a constant, variable, template of these types or array. In the case of record of and set of values or templates or arrays, the actual value to be returned is the sequential number of the last defined element (index of that element plus 1).

Related keyword:

- integer
- record
- set
- template

### sizeof(structured_type value) return integer

- Only elements of the TTCN-3 object, which is the parameter of the function are calculated; i.e. no elements of nested types/values are taken into account at determining the return value.

Example 1:

type record MyPDU
{ boolean field1 optional,
integer field2
};
type record of integer MyPDU1;
const MyPDU MyConst :=
{ field1 := true,
field2 := 29
};
template MyPDU MyTemplate :=
{ field1 := omit,
field2 := 5
};
var integer numElements;

...

numElements := sizeof(MyConst); // returns 2
numElements := sizeof(MyTemplate); // returns 1

Example 2:

type record of integer MyRecord;
var MyRecord MyRecordVar;
MyRecordVar := { 0, 1, -, 2 };

...

numElements := sizeof(MyRecordVar);
// returns 4 without respect to the fact, that the element MyRecordVar[2] is undefined