I seem to be making some sort of basic mistake. I can't get the variables to come back again. I attach the files pcallc.p, ccall.c, ccall.h and Makefile. The Pascal program does not get the value 56 back (nor would I expect it to, because it has been passed by value). I have tried various permutations of the use of pointers, but none of them seem to work.
How can I change my simple program to get the value 56 back from the C function?
I'll again be grateful for your advice.
Thanks, Chris
pcallc.p [ program pascalcallsC(input,output);
procedure world; external name 'world'; procedure w1(i : integer); external name 'w1';
var i : integer; begin writeln("Hello world from Pascal"); world; writeln("Returned from C to Pascal\n"); i := 96; w1(i); writeln("Returned from C again I = ",i); end. ]
ccall.c: [ #include <stdio.h> #include "ccall.h"
void world (void) { printf("\nHello World from C\n"); }
void w1 (int i) { printf("Hello again from C i = %i\n",i); i = 56; } ]
ccall.h: [ extern void world(void); extern void w1(int i); ]
Makefile: [ pcallc : pcallc.p ccall.o gpc -o pcallc pcallc.p ccall.o ccall.o : ccall.c gcc -c ccall.c clean: rm *.o pcallc ccall.o ]
Dr Christian Hicks Senior Lecturer, School of Mechanical & Systems Engineering, Stephenson Building, University of Newcastle upon Tyne, NE1 7RU. Phone: +44 191 222 6238 Mobile 0795 8317804 Fax: + 44 191 222 8600 Homepage: http://www.staff.ncl.ac.uk/chris.hicks
Hi!
On Sun, Nov 16, 2003 at 07:50:16PM +0000, Dr Christian Hicks wrote:
How can I change my simple program to get the value 56 back from the C function?
Try this:
pascal-code: [ program pastest; var i: Integer;
procedure W1 (var i: Integer); external name 'c_w1';
begin i := 100; WriteLn ('i is: ', i); W1 (i); WriteLn ('i is: ', i) end. ]
c-code [ void c_w1 (int *i) { (*i) = 50; } ]
Eike