SPL to HP C/XL Migration Guide (30231-90001)
9- 2
Example
Since all I/O operations by MPE V intrinsics use 16-bit data, it is
common to equivalence a BYTE array to a previously declared LOGICAL word
array. Then data is stored into or extracted from the byte array, while
the equivalent word array is passed to the MPE V intrinsics.
As an example of the convenience of the HP C/XL constructs, consider the
following SPL program fragment and the identical operation in HP C/XL:
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| | |
| LOGICAL ARRAY BUFW(0:40); | short int X; |
| <<equate byte to word array>> | printf("value of X = %d\n",X); |
| BYTE ARRAY BUF(*)=BUFW; | |
| INTEGER X; | |
| INTRINSIC PRINT, ASCII; | |
| <<move 18 bytes>> | |
| MOVE BUF:="value of X = "; | |
| <<convert to ASCII>> | |
| ASCII(X,10,BUF(13)); | |
| <<output word array copy>> | |
| PRINT(BUFW,9,0); | |
| | |
---------------------------------------------------------------------------------------------
Record Format
The "normal" SPL file has fixed-length records, although files with
variable length records can be created and used. The "normal" HP C/XL
file, called a "stream", has variable-length records; files with
fixed-length records can be created and used.
File References
There are
three
distinct variables that specify a file, depending on
which HP C/XL function or MPE intrinsic opened it. These variables are
used to identify the file access to other functions or intrinsics. The
HP C/XL function open returns
filedes
, an int file descriptor; the HP
C/XL function fopen returns
stream
, a pointer to type FILE; and the MPE
intrinsic FOPEN returns
filenum
, a 16-bit integer file number. The MPE
XL intrinsic HPFOPEN also returns
filenum
, but as a 32-bit integer file
number, equal to the FOPEN value.
Fortunately, there is a relationship among them. A
stream
file pointer
can be obtained from a
fildes
file descriptor with the HP C/XL <stdio.h>
library function fdopen:
#include <stdio.h>
stream
= fdopen(
fildes
)
An MPE
filenum
can be obtained from
fildes
with the HP C/XL <mpe.h>
library function _mpe_fileno: