HP SunSoft Pascal 4.0 Manuel d'utilisateur Page 158

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 333
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 157
134 Pascal 4.0 Users 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 }
Vue de la page 157
1 2 ... 153 154 155 156 157 158 159 160 161 162 163 ... 332 333

Commentaires sur ces manuels

Pas de commentaire