File-Passing Between Pascal And C - Sun Microsystems SunSoft Pascal 4.0 User Manual

Hewlett-packard user guide printer printer
Table of Contents

Advertisement

6
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.

File-Passing Between Pascal and C

The C procedure,
UseFilePtr.c
The Pascal main program,
UseFilePtrMain.p
134
hostname% pc -c GloVar.p
hostname% cc GloVar.o GloVarMain.c
hostname% a.out
2001
You can pass a file pointer from Pascal to C, then have C do the I/O, as in:
#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") ;
}
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);
UseFilePtr(cfile);
end. { UseFilePtrMain }
Pascal 4.0 User's Guide
{ Get a file pointer. }
{ Call the C function. }

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the SunSoft Pascal 4.0 and is the answer not in the manual?

Questions and answers

Table of Contents