On 15 Nov 2003 at 20:55, Dr Christian Hicks wrote:
I have a lot of code which I am wanting to port from Sun's Sparcworks. The main algorithms are in Pascal, but the user interface was written in XView which was linked in via C.
In Sparcworks, linking from Pascal to C involves statements of the following form:
PROCEDURE X_SelAlgorithmn(VAR select_no : integer; VAR smess: string); external c;
This is calling a C function which is returning values for select_no and smess.
Some of my calls included a lot of variables which were set by a complicated form e.g. procedure x_rscinput_form(mc_code: string; var mc_name: string; var efficiency, d_rule_a, avail_ops, shifts, children, dist_rule_b: integer; var x_pos, y_pos, x_size, y_size: real; var tr_dev, audit_p, update_p: integer; var opt_mc_code: string; var hour_rate, ohead_rate: real; var minsu, minmc, mintr, batchsize, transfer, optmcrule: integer; var dist: boolean; var co_name: string); external c;
Thus returning lots of variables with different types from C to Pascal.
With GNU Pascal (thanks to the African Cheif and Kevan) I can pass variables from Pascal to C and I can get single variables back again. Is there a way that I can pass multiple variables into C and back into Pascal without resorting to global variable or using files?
I don't think that it is any different in gpc. You simply use parameter lists, as above. The main things to watch for are data types that might mean different things or that don't exist, and the size of data types. For example, I am not sure that the "Real" type means anything in C. But perhaps "Single" and "Double" mean the same thing in gcc as they mean in gpc - if so, then you could use either of them instead of "Real".
"Integer" in gpc probably means the same thing as "int" in gcc, as long as it is the same platform.
"Var foo:String" means nothing to a gcc compiler, AFAICS. To pass string variables to and fro, you will need to use the "PChar" or "CString" type in gpc. This is roughly equivalent to "char *foo" in gcc, or perhaps also "char foo[size]" (or at least they should all be type-compatible if passed as parameters). People from a Windows background are accustomed to using PChar types for interfacing with the Windows API, which expects C-style parameters. If you are not, then you have to get used to the gpc functions (in the "gpc" and "strings" unita) for dealing with null terminated strings (e.g., strcopy, strlen, strpas, strpcopy, strcat). Most of these are used freely in C and so would pose no problem to a C programmer.
For passing Pascal records, I think you will need to use pointers to structs or something like that.
Can't think of anything else ... except perhaps file parameters - and I can't help you there. I wouldn't know what to do with them in this context.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~african_chief/