134
Pascal 4.0 User’s Guide
6
File-Passing Between Pascal and C
You can pass a file pointer from Pascal to C, then have C do the I/O, as in:
The commands to compile and
execute
GloVar.p
and
GloVarMain.c
without
–xl
.
With
-xl
, the Pascal
integer
must be paired with a C
short
int
and declared
public
since
the default visibility is
private
.
hostname% pc -c GloVar.p
hostname% cc GloVar.o GloVarMain.c
hostname% a.out
2001
The C procedure,
UseFilePtr.c
#include <stdio.h>
void UseFilePtr (FILE *ptr)
{
{ /* Write to the file: */
fprintf( ptr, "[1] Passing the file descriptor \n") ;
fprintf( ptr, "[2] and writing information \n") ;
fprintf( ptr, "[3] to a file \n") ;
}
The Pascal main program,
UseFilePtrMain.p
program UseFilePtrMain;
var
f: text;
cfile: univ_ptr;
procedure UseFilePtr(cf: univ_ptr); external c;
begin
rewrite(f, 'myfile.data'); { Make the file. }
cfile := getfile(f); { Get a file pointer. }
UseFilePtr(cfile); { Call the C function. }
end. { UseFilePtrMain }
Содержание SunSoft Pascal 4.0
Страница 14: ...xiv Pascal 4 0 User s Guide ...
Страница 16: ...xvi Pascal 4 0 User s Guide ...
Страница 30: ...6 Pascal 4 0 User s Guide 1 ...
Страница 160: ...136 Pascal 4 0 User s Guide 6 ...
Страница 268: ...244 Pascal 4 0 User s Guide 11 ...
Страница 320: ...296 Pascal 4 0 User s Guide B ...
Страница 331: ...Index 307 ...
Страница 333: ......