# const

> 1. Declaring a constant of built-in type

> 2. Declaring a constant of referenced type

> 3. Multiple declaration of constants of the same type

> 4. Declaring a constant array

> 5. Declaring an external constant

#### 1. Declaring a constant of built-in type

### const ( bitstring | boolean | charstring | universal charstring | integer | octetstring | objid | hexstring | verdicttype | float | address | default | anytype ) const_identifier := single_constant_expression ;

- The const keyword introduces the constant definition.

- bitstring denotes an a type whose distinguished values are the ordered sequences of zero, one, or more bits.

- boolean is a simple basic type consisting of two distinguished values (namely true or false).

- charstring denotes a type whose distinguished values are the ordered sequences of characters of ISO/IEC 646 as described in ITU-T Recommendation T.50.

- universal charstring denotes a type whose distinguished values are the ordered sequences of UCS-4 coded representation of ISO/IEC 10646 characters.

- integer denotes a a type with distinguished values which are the positive and negative whole numbers, including zero.

- octetstring stands for a a type whose distinguished values are the ordered sequences of zero or a positive even number of hexadecimal digits (every pair of digits corresponding to an ordered sequence of eight bits).

- objid defines a type whose distinguished values are the set of all object identifiers conforming to clause 6.2 of ITU-T Recommendation X.660.

- hexstring defines a type whose distinguished values are the ordered sequences of zero, one, or more hexadecimal digits, each corresponding to an ordered sequence of four bits.

- verdicttype defines a type for use with test verdicts consisting of 5 distinguished values.

- float defines a type to describe floating-point numbers.

- address denotes a user defined type to allow addressing specific entities inside the system under test.

- default is a reference to an activated default resulting from an activate operation.

> TITAN specific restriction compared to the standard: anytype is not implemented yet.

- anytype defines as a shorthand for the union of all defined types, imported ASN.1 and other imported external types.

- const_identifier is the name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.
  According to the Naming convention, the following prefixes are recommended:

  - cg_ for global constants (defined in the module declaration part),
  - c_ for constants declared in componets and

  - cl_ for constants declared elsewhere.

- single_constant_expression may contain constants and literal values as operands. The result of the expression must correspond to the type of the constant.

Example

#### 2. Declaring a constant of referenced type

### const [ module_id [.obj_id ].] type_reference [.field_reference ] const_identifier :=
(single_constant_expression | value_list | value_assginment_list);

- The const keyword introduces the constant definition.

- module_id is needed when the referenced type is defined in another TTCN-3 module and denotes the name of that module.

> TITAN specific restriction compared to the standard: objid is not implemented yet; it is discarded when encountered.

- obj_id is an optional object identifier which may follow the TTCN-3 module identifier.

- type_reference refers to an already defined (structured or simple) type.

> TITAN specific restriction compared to the standard: field reference can only be used with structured constants defined in the module definition part.

- field_reference optionally stands for a field of a structured type.

- const_identifier is the name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.

- single_constant_expression may contain constants and literal values as operands. The result of the expression must correspond to the type of the constant. Used with simple types.

- value_list is a comma-separated list of the constant values between curly brackets. Used with structured types.

> TITAN specific restriction compared to the standard: value assignment can only be used with structured constants defined in the module definition part.

- value_assignment_list is a comma-separated list of the field name - constant value pairs between curly brackets. Used with structured types.

Example

#### 3. Multiple declaration of constants of the same type

### const type identifier1 := constant_expression1, identifier2 := constant_expression2 â¦ ;

- The const keyword introduces the constant definition.

- type is one of the built-in types mentioned in paragraph 1 or referenced types mentioned in paragraph 2 .

- identifiern is the name used to refer to the nth constant.

- constant_expressionn determines the value of the nth constant.

Example

#### 4. Declaring a constant array

### const type const_identifier [ array_index ] := value_list;

- The const keyword introduces the constant definition.

- type is one of the built-in types mentioned in paragraph 1 or referenced types mentioned in paragraph 2 .

- const_identifier is the name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.

- array index is a non-negative integer value corresponding to the number of elements in the array.
  Alternatively, the lower and upper index values are given joined by two dots.

- value_list is a comma-separated list of the constant values between curly brackets.

Example

#### 5. Declaring an external constant

### external const type const_identifier ;

- The external keyword means that the constant is defined in a module other than TTCN-3 or ASN.1 (for example in a module written in C++).

- The const keyword introduces the constant definition.

- type is one of the built-in types mentioned in paragraph 1 or referenced types mentioned in paragraph 2 .

- const_identifier is the name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.

Example

Example 1a:

const integer c_myConstant := 127;

A constant called c_MyConstant is defined. The constant will have the value one hundred twenty seven.

Example 1b:

const bitstring c_myGarland := '00101101'B;
const bitstring c_myBiggerGarland := c_myGarland & '11000010'B;

Two constants are defined. The one called c_myBiggerGarland will have the binary value 11101111.

Example 2a:

type record E_Rec {integer field1, boolean field2}; //defined in Elsewhere

const Elsewhere.E_Rec c_CurrConst := {17, true};

A record called E_Rec have been defined in the TTCN-3 module Elsewhere. In the current module we define a constant named c_CurrConst and assign values to all of its fields. In TITAN, the value notation as shown above may only be used in the module definition part.

Example 2b:

type record G_Rec {float first_field, hexstring last_field};
const G_Rec.last_field c_FuzerConst := 'AA'H;

First we define a record called G_Rec. Then we define a constant named c_FuzerConst derived from the second field of the referred type and assign the hexadecimal value AA to it.

Example 2c:

type record G_Rec {float first_field, hexstring last_field};
const G_Rec c_UeppigConst := {
first_field := 5.77,
last_field := '55'H;
}

First we define a record called G_Rec. Then we define a constant named c_UeppigConst and assign values to both of its fields using assignment notation.

Example 3:

const boolean c_MyConst2 := true, c_MyConst3 := false;

Two constants (c_MyConst2 and c_MyConst3) are declared within one operation.

Example 4a:

const boolean c_MinConst[3] := { true, false, false };

The array defined c_MinConst consists of three elements indexed from 0 to 2.

Example 4b:

const boolean c_DinConst[7..9] := { true, false, false };

The array defined c_DinConst consists also of three elements as in the example 4a, but here the indices run from 7 to 9.

Example 5:

external const objid MonConst;

The constant called MonConst (an object identifier) is defined in an external module, e.g. in a module written in C++.

BNF definition of const