Copyright © 1996, 1997 Lucent Technologies Inc. All rights reserved.

6.1 Data declarations

These forms constitute the basic way to declare and initialize data:


identifier-list : type ; identifier-list : type = expression ;
A comma-separated sequence of identifiers is followed by a colon and then the name of a type. Each identifier is declared as having that type and denotes a particular object for rest of its scope (see §11 below). If the declaration contains = and an expression, the type must be a data type, and all the objects are initialized from the value of the expression. In a declaration at the top level (outside of a function), the expression must be constant (see §8.5) or an array initialized with constant expressions; the bound of any array must be a constant expression. Lists and ref adt types may not be initialized at the top level. If an object is not explicitly initialized, then it is always set to nil if it has a reference type; if it has arithmetic type, then it is set to 0 at the top level and is undefined if it occurs within a function.

For example,

	i, j: int = 1;
	r, s: real = 1.0;
declares i and j as integers, r and s as real. It sets i and j to 1, and r and s to 1.0.

Another kind of declaration is a shorthand. In either of


identifier := expression ; ( identifier-list ) := expression ;
identifiers on the left are declared using the type of the expression, and are initialized with the value of the expression. In the second case, the expression must be a tuple or an adt, and the types and values attributed to the identifiers in the list are taken from the members of the tuple, or the data members of the adt respectively. For example,
	x: int = 1;
and
	x := 1;
are the same. Similarly,
	(p, q) := (1, 2.1);
declares the identifiers on the left as int and real and initializes them to 1 and 2.1 respectively. Declarations with := can also be expressions, and are discussed again in §8.4.4 below.

05/Jun/97