HP Pascal/iX Reference Manual (31502-90022)

4-: 14
* If one operand is a char expression, the other may be a char
expression or a single-character string literal.
Table 4-4 summarizes these rules. The standard function
strmax(s)
returns the maximum length of the string variable s. The standard
function
strlen(s)
returns the current length of the string expression s.
A string constant is considered a string literal when it appears on
either side of a relational operator.
Table 4-4. String, PAC, Char, String Literal Comparison
------------------------------------------------------------------------------------------------
||||||
| A <relop> B | string | PAC | char | string literal |
||||||
------------------------------------------------------------------------------------------------
||||||
| string | Length of | Not allowed | Not allowed | Length of |
| | comparison | | | comparison |
| | based on | | | based on |
| | smaller
strlen
| | | smaller
strlen
|
||||||
------------------------------------------------------------------------------------------------
||||||
| PAC | Not allowed | The shorter | Not allowed | The shorter |
| | | of the two | | of the two |
| | | is padded | | is padded |
| | | with blanks | | with blanks |
||||||
------------------------------------------------------------------------------------------------
||||||
| char | Not allowed | Not allowed | Yes | Only if |
| | | | | strlen(B)=1 |
||||||
------------------------------------------------------------------------------------------------
||||||
| string literal | Length of | The shorter | Only if | The shorter |
| | comparison | of the two | strlen(A)=1 | of the two |
| | based on | is padded | | is padded |
| | smaller
strlen
| with blanks | | with blanks |
||||||
------------------------------------------------------------------------------------------------
Example
PROGRAM show_string_relational (output) ;
VAR
s,t: string[80];
pac: packed array [1..5] of char;
chr: char;
b: boolean;
BEGIN
s:='abc';
t:='ab';
if s > t then b:=true {string to string comparison. this is}
else b:=false; { the same as b:= s > t }
writeln (b);
b:= s > 'ab'; {string to string literal comparison }
writeln (b);
pac:='abc';
b:= pac > 'abc'; {PAC to string literal comparison }
writeln (b);
chr:= 'A';
b:= 'c' > chr; {char to string literal comparison }
writeln (b);
END.
Output: