162
Pascal 4.0 User’s Guide
7
Pascal File Pointers to C++
You can pass a file pointer from Pascal to C++, then have C++ do the I/O. See
this example.
The C++ procedure,
UseFilePtr.cc
#include <stdio.h>
extern "C"
void UseFilePtr (FILE* ptr)
{
fprintf (ptr, "[1] \n");
fprintf (ptr, "[2] \n");
fprintf (ptr, "[3] \n");
}
The C++ main program,
UseFilePtrMain.p
program UseFilePtrMain (output);
var
f: text;
cfile: univ_ptr;
procedure UseFilePtr (cf: univ_ptr); external C;
begin
rewrite (f, 'myfile.data');
cfile := getfile (f);
UseFilePtr (cfile);
end.
The commands to compile and
execute
UseFilePtr.cc
and
UseFilePtrMain.p
hostname% CC -c UseFilePtr.cc
hostname% pc UseFilePtr.o UseFilePtrMain.p
hostname% a.out
[1]
[2]
[3]
Содержание 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: ......