Titan



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 ;

   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.

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);

   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.

   TITAN specific restriction compared to the standard: field reference can only be used with structured constants defined in the module definition part.
   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 ;

Example


4. Declaring a constant array


const type const_identifier [ array_index ] := value_list;

Example


5. Declaring an external constant


external const type const_identifier ;

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