Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site umcp-cs.UUCP Path: utzoo!watmath!clyde!floyd!harpo!seismo!rlgvax!cvl!umcp-cs!chris From: chris@umcp-cs.UUCP Newsgroups: net.lang.c,net.lang.f77,net.unix-wizards Subject: Re: linking c and f77 programs [and pascal programs] Message-ID: <6423@umcp-cs.UUCP> Date: Thu, 5-Apr-84 02:02:43 EST Article-I.D.: umcp-cs.6423 Posted: Thu Apr 5 02:02:43 1984 Date-Received: Sat, 7-Apr-84 02:28:06 EST References: <2123@tektronix.UUCP> <868@linus.UUCP> Organization: Univ. of Maryland, Computer Science Dept. Lines: 90 In *.*BSD (and probably therefore System *), if you want to call a C subroutine from F77 code, write the C subroutine normally, but change parameter types: f77 type C type -------- ------ integer int * integer*2 short * real*4 float * real*8 double * complex*8 struct complex * complex*16 struct dcomplex * struct complex { float re, im; }; struct dcomplex { double re, im; }; Also, if the f77 routine wants to call "foo", name the C routine "foo_". Return values should just be return'ed (with the appropriate type) in the case of integer and real*8. I'm not sure about the others. Example: program test integer i, j integer function cfunc do 10 i = 1, 100 j = cfunc (i) 10 continue end int cfunc_ (i) int *i; { ; return retval; } -------- To call Fortran routines from Pascal is considerably more difficult, because Pascal won't let you use "_" in identifiers. (#@%^*$&) One method is to use a C interface routine: to call f77 function "func" from pascal: integer function func (i, j, k) integer i, j, k ... return end int xfunc (i, j, k) /* x-ecute f77 "func" */ int *i, *j, *k; { return func_ (i, j, k); } { I'm rather rusty on Pascal; ignore minor syntactic mistakes } function xfunc (var i, j, k : integer) : integer external; program prog (input, output); begin ... xfunc (...); ... end. Note also that if you don't want the hassle of providing "var" parameters, you can have your C code written like this: int xfunc (i, j, k) int i, j, k; { return func_ (&i, &j, &k); } This implies that even if the Fortran function modifies its parameters, it can't affect the Pascal values. Chris -- In-Real-Life: Chris Torek, Univ of MD Comp Sci UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris.umcp-cs@CSNet-Relay