To Index

 Documented in Volume 1 of the UNIX Programmers Manual.
 See /usr/doc/pascal/ on 4.2 BSD systems for additional online documentation on this.


  From Dennis Cottel:
                       Calling C from Pascal.
     The way this is done is to use the external compilation facility
  of 'pc' as described on page 42 of the Berkeley Pascal User's Manual,
  where C routines are called instead of Pascal routines.  The only
  trick to remember is that C passes all routine arguments by reference,
  so in the Pascal routine declarations, all arguments must be 'var'
  arguments.  The following is a small example.
     To run it, compile the C routine using the -c option so the file
  add.o is left.  Then call 'pc main.p add.o' to compile the Pascal
  part and link it to the C part.

  .........file add.c..........

  add(i, j)
    int i, j;
    {	return(i + j);	}

  addp(i, j, k)
    int i, j, *k;
    {	*k = i + j;	}

  .........file add.h..........

  function add(var i, j: integer): integer;
  	external;

  procedure addp(var i, j: integer; var k: integer);
  	external;

  .........file main.p...........

  program mainprog(output); {Pascal program calling C}
  var i, j, k: integer;
  #include "add.h"

  begin
  writeln('Pascal program started');

  {try a function to add two integers}
  i := 4; j := 5;
  writeln('i=4 + j=5 = ', add(i, j));

  {try a procedure returning an argument}
  i := 4; j := 5;
  addp(i, j, k);
  writeln('addp(i,j,k) gives k = ', k);

  writeln('Pascal program complete');
  end.


To Index