Assignment Compatibility [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation
HP Pascal/iX Reference Manual
Assignment Compatibility
A value of type T2 may only be assigned to a variable or function result
of type T1 if T2 is assignment compatible with T1. For T2 to be
assignment compatible with T1, any of the following conditions must be
true:
* T1 and T2 are type compatible types that are neither files nor
structures that contain files.
* T1 is real or longreal, and T2 is integer or an integer subrange.
The compiler converts T2 to real or longreal prior to assignment.
* T1 is longreal and T2 is real. The compiler converts T2 to
longreal prior to assignment.
* T1 is real and T2 is longreal. The compiler rounds T2 to the
precision of T1 prior to assignment.
Furthermore, a run-time or compile-time error occurs if the following
restrictions are not observed:
* If T1 and T2 are type compatible ordinal types, the value of type
T2 must be in the closed interval specified by T1.
* If T1 and T2 are type compatible set types, all the members of the
value of type T2 must be in the closed interval specified by the
base type of T1.
* A special set of restrictions applies to assignment of string
literals or variables of type string, PAC, or char.
NOTE The pointer constant NIL is both type compatible and assignment
compatible with any pointer type. Likewise, the empty set ( [ ] )
is both type compatible and assignment compatible with any set
type.
String Assignment Compatibility
Certain restrictions apply to the assignment of string literals or
variables of the type string, PAC, or char. These restrictions are
listed below.
* If T1 is a string variable, T2 must be a string variable or a
string literal whose length is equal to or less than the maximum
length of T1. T2 cannot be a PAC or char variable. Assignment
sets the current length of T1.
* If T1 is a PAC variable, T2 must be a PAC or a string literal
whose current length is less than or equal to the length of T1.
T1 is blank filled if T2 is a string literal or PAC that is
shorter than T1. T2 cannot be a string or a char variable.
* If T1 is a char variable, T2 may be a char variable or a string
literal with a single character. T2 cannot be a string or PAC
variable.
Table 3-1 summarizes these rules. The standard function strmax(s)
returns the maximum length of the string s. The standard function
strlen(s) returns the current length of the string s or the number of
characters in the PACs.
String constants are considered string literals when they appear on the
right side of an assignment statement. Any string operation on two
string literals, such as the concatenation of two string literals,
results in a string of type string.
Table 3-1. String, PAC, and String Literal Assignment
-----------------------------------------------------------------------------------------------------
| | | | | |
| T1:=T2 | string | PAC | char | String Literal |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| string | Only if | Not allowed | Not allowed | Only if |
| | strmax(T1)>= | | | strmax(T1)>= |
| | strlen(T2) | | | strlen(T2) |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| PAC | Not allowed | Only if | Not allowed | Only if |
| | | strlen (T1) >= | | strlen (T1) >= |
| | | strlen (T2) | | strlen(T2) |
| | | T1 is padded | | T1 is padded |
| | | with blanks | | with blanks |
| | | if necessary | | if necessary |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| char | Not allowed | Not allowed | Yes | Only if |
| | | | | strlen(T2)=1 |
| | | | | |
-----------------------------------------------------------------------------------------------------
MPE/iX 5.0 Documentation