Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site hao.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!trwrba!cepu!hao!woods From: woods@hao.UUCP (Greg "Bucket" Woods) Newsgroups: net.lang.f77,net.lang.c Subject: Re: calling c routines from fortran Message-ID: <1265@hao.UUCP> Date: Mon, 19-Nov-84 13:24:18 EST Article-I.D.: hao.1265 Posted: Mon Nov 19 13:24:18 1984 Date-Received: Wed, 21-Nov-84 01:33:31 EST References: <100@athena.UUCP> Organization: High Altitude Obs./NCAR, Boulder CO Lines: 36 Xref: sdcsvax net.lang.f77:161 net.lang.c:3263 > Has anyone had experience with calling c routines from fortran 77 on 4.2 > unix? Know of any articles, pitfalls? Unfortunately, due to the fact that F77 insists on appending a "_" to all of it's routine names, you cannot call *any* C routine from F77 unless it's name ends in "_". In addition to that, all F77 arguments are pointers, so you can't even call a routine whose name ends in "_" if it is expecting any non- pointer arguments (usually the case in C). Therefore, the only way to do this is the following (which is what I gather Liz was suggesting) (suppose you want to call routine "z" which returns an int and has one int argument): .... iretvl=iz(intvar) .... int iz_(intvar) int *intvar; { int z(); /* this declaration not necessary for int functions */ return(z(*intvar)); } I know this is kludgy, but I use it all the time and it works fine. It's the only thing you can do (well, maybe you could write the intermediate routine in assembly, but I doubt if you could gain much efficiency that way, and it's a lot more confusing). For a reference, see the paper "A Portable Fortran 77 Compiler" by S. I. Feldman and P.J. Weinberger, which, among other places, appears in the "Volume 2C" manual which came with our 4.2BSD manuals. --Greg "FORTRAN hacker" Woods -- {ucbvax!hplabs | allegra!nbires | decvax!stcvax | harpo!seismo | ihnp4!stcvax} !hao!woods "...once in a while you can get shown the light in the strangest of places if you look at it right..."