SPL to HP C/XL Migration Guide (30231-90001)

5-29
IF Expressions
Table 5-27. IF Expressions
---------------------------------------------------------------------------------------------
|||
| SPL | HP C/XL Equivalent |
|||
---------------------------------------------------------------------------------------------
|||
|
if-expression
:|
conditional-expression
:|
|||
|IF
condition-clause
THEN
true-expression
|
condition-clause
?
true expression
|
| ELSE
false-expression
|:
false-expression
|
|||
---------------------------------------------------------------------------------------------
|||
| Example: | Example: |
|||
| X + (IF A < B THEN 5 ELSE 6) | X + (A <B?5:6) |
|||
---------------------------------------------------------------------------------------------
| |
| In both cases above, the expression evaluates to X+5 if the condition clause "A < B" |
| is true; otherwise, it evaluates to X+6. |
| |
---------------------------------------------------------------------------------------------
|||
| An IF expression may be used in any | Same as SPL. |
| expression where the value of the result is | |
| allowed. | |
|||
---------------------------------------------------------------------------------------------
The HP C/XL syntax may look cryptic to SPL programmers. It can be
beneficial to add parentheses to make the sections stand out, such as:
X + ( (A < B) ? ( 5 ) : ( 6 ) )
The HP C/XL "? :" conditional expression has lower precedence than "||"
(logical OR) and higher precedence than "=" (assignment).
Assignment Statement
Table 5-28. Assignment Statement
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
|
assignment-statement
: |
assignment-statement
: |
| 1.
variable
| 1.
variable
|
| [:=
variable
][...] :=
expression
| [=
variable
][...] =
expression
; |
| 2.
variable
(
left-bit
:
len
) | 2.
(No direct equivalent;
|
| [:=
variable
][...] :=
expression
|
see
BDEPOSIT
function below.)
|
| | Note: The HP C/XL assignment operator, "=",|
| | is the same as the SPL equality operator. |
| | |
---------------------------------------------------------------------------------------------
| | |
| The type of
expression
may be different from| The types of the
variable
s and
expression
|
| the types of the
variable
s and they may be | may be different They do not have to have |
| different from each other, except they must | the same length. HP C/XL performs automatic|
| all be the same length. Type BYTE is treate| type conversions as assignment proceeds from|
| as a 16-bit quantity. | right to left. |
| | |
---------------------------------------------------------------------------------------------
| | |
| The leftmost assigned-to variable may | Bit-field assignment is not allowed. |