I am beginning to make some progress (thanks for your help so far), but would be very grateful for some more help.
My attempts at producing the XView - Pascal code are in Makefile, p.p, x_message.c and x_message.h.
When I try to compile I get: $ make gpc -c p.p p.p: In main program: p.p:11: error: argument to `WriteLn' is of wrong type p.p:11: error: (Use `--cstrings-as-strings' to treat `CString' as a string.) make: *** [p.o] Error 1
I based this code on various examples, including some that demonstrated passing strings between C and Pascal that I produced with the Chief's help back in 2003 (http://www.staff.ncl.ac.uk/chris.hicks/programming.htm, pcallsc2 <http://www.staff.ncl.ac.uk/chris.hicks/programming.htm, pcallsc2> near the bottom).
I don't understand what is happening here. My Writeln is similar to the 2003 example that worked, likewise I am not sure why the --cstrings-as-strings is not working. I am also wondering whether the Pascal in the 2003 example was quite right. Does the second getmem release the memory? program pascalcallsC(input,output);
procedure world; external name 'c_world'; procedure w1(var i : integer; s : pchar); external name 'c_w1';
var i : integer; s : pchar; begin writeln("Hello world from Pascal"); world; writeln("Returned from C to Pascal\n"); i := 96; getmem (s, 260); { ahem - we need to allocate memory } w1(i,s); writeln("Returned from C again I = ",i); writeln("Return from C cstring = ",s); getmem (s, 260); { free this here, else memory leak on next line } s := "This is a CString"; { not really a good idea, IMHO } writeln("Trying out pascal ",s); end. Many thanks, Chris.