These worked examples show VX/PASCAL rewriting real OpenVMS Pascal constructs into ANSI C++.
The identifiers use a banking demo estate; the syntax is exactly the kind of change the
translation applies.
VMS strings and a system service
A routine declares a VMS VARYING string, a fixed packed-array string, and an
external OpenVMS system service with by-descriptor arguments and immediate defaults:
TYPE
VString255_t = Varying[255] of Char;
PString80_t = Packed Array[1..80] OF Char;
[ASYNCHRONOUS,EXTERNAL(SYS$ASCTIM)] FUNCTION $ASCTIM (
VAR TIMLEN : [VOLATILE] $UWORD := %IMMED 0;
VAR TIMBUF : [CLASS_S,VOLATILE] Packed Array[$l2..$u2:INTEGER] OF Char;
TIMADR : $UQUAD := %IMMED 0) : INTEGER; EXTERNAL;
VAR
Stmt_Time : PString80_t;
Stmt_Display : VString255_t;
Length_Time : [WORD] 0..65535 := 0;becomes:
#include "VxPascal.hxx"
extern "C" int32_t sys$asctim(
$UWORD* TIMLEN = 0,
DXX* TIMBUF = NULL,
$UQUAD* TIMADR = 0) ;
typedef _VaryingString<255> VString255_t ;
typedef _FixedString<1,80> PString80_t ;
PString80_t Stmt_Time;
VString255_t Stmt_Display;
uint16_t Length_Time = 0;
The VARYING and packed-array string types become the _VaryingString
and _FixedString runtime templates, the [CLASS_S] descriptor
parameter is bridged to the runtime DXX descriptor class, and the external VMS
service is emitted as an extern "C" prototype whose := %IMMED 0
defaults become C++ default arguments.
Program body and string operations
BEGIN
$ASCTIM (TIMLEN := Length_Time, TIMBUF := Stmt_Time);
Stmt_Display := SUBSTR(Stmt_Time, 1, Length_Time);
WRITELN ('Statement time [', Stmt_Time, ']');
END.becomes:
int main(int argc, const char *argv[])
{
sys$asctim(&Length_Time, Stmt_Time);
Stmt_Display = Substr(Stmt_Time, 1, (Length_Time));
Writeln(VXP_OUTPUT, E_CONTINUE, "%s%D%c",
"Statement time [", (DXX *)(Stmt_Time), ']');
vxrt_exit(0);
}
The BEGIN ... END. block becomes int main, SUBSTR and
WRITELN resolve to their runtime entry points, string arguments are passed as
DXX descriptors, and the program terminates through vxrt_exit so
the exit status is reported to the host as it was on OpenVMS.
Variant records
A Pascal variant record keeps its tag and case structure as a C++ struct with an anonymous
union, so overlaid layouts such as a transaction record carry across without hand editing:
TYPE
Txn_t = RECORD
Account : INTEGER;
CASE Kind : Txn_Kind OF
Debit : (Amount : INTEGER);
Detail : (Ref_Text : Varying[40] of Char);
END;
The fixed fields become struct members and the CASE variants become an anonymous
union of the alternative layouts, preserving the original storage overlay.