Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Union type

Union type 22 Oct 2008 10:55 #7469

  • Iv
  • Iv's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Karma: 0
Hi to everynoe,
I am with my colleague Elena studying the union type and we have find a thing
in the standar we are not able to resolve. At page 39 of the Core Language
V3.2.1 is an example on how to declare and use an union type.

6.3.5.0 General
TTCN-3 supports the union type. The union type is a collection of fields, each
one identified by an identifier. Only
one of the specified fields will ever be present in an actual union value. Union
types are useful to model a structure
which can take one of a finite number of known types.

EXAMPLE:
type union MyUnionType
{
integer number,
charstring string
};
// A valid instantiation of MyUnionType would be
var MyUnionType age, oneYearOlder;
var integer ageInMonths;
age.number := 34; // value notation by referencing the field. Note, that this
// notation makes the given field to be the chosen one
oneYearOlder := {number := age.number+1};
ageInMonths := age.number * 12;

The value list notation for setting values shall not be used for values of union
types.
The instruction we do not understand is " oneYearOlder := {number :=
age.number+1}; ", because the last line of of the point 6.3.5.0 says the list
notation is not supported by a union type. Is the example incorrect?
The administrator has disabled public write access.

Union type 22 Oct 2008 11:43 #7470

Hello Ivan,

>Hi to everynoe,
> I am with my colleague Elena studying the union type and we have find a
>thing in the standar we are not able to resolve. At page 39 of the Core
>Language V3.2.1 is an example on how to declare and use an union type.

> ...

>The instruction we do not understand is " oneYearOlder := {number :=
>age.number+1}; ", because the last line of of the point 6.3.5.0 says the
>list notation is not supported by a union type. Is the example incorrect?

The curly brackets "{" in this case do not depict a list but instead a
template specification. Thus, there is no conflict with the list notation.

Cheers,
Bernard
The administrator has disabled public write access.
  • Page:
  • 1

FacebookTwitterGoogle BookmarksRedditNewsvineTechnoratiLinkedin