Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!caip!clyde!cbatt!cbosgd!ihnp4!cuae2!ltuxa!ttrdc!levy From: levy@ttrdc.UUCP (Daniel R. Levy) Newsgroups: net.unix-wizards Subject: Re: linking C and Fortran Message-ID: <1103@ttrdc.UUCP> Date: Sat, 2-Aug-86 17:44:32 EDT Article-I.D.: ttrdc.1103 Posted: Sat Aug 2 17:44:32 1986 Date-Received: Mon, 4-Aug-86 00:49:26 EDT References: <2668@brl-smoke.ARPA> Organization: AT&T, Computer Systems Division, Skokie, IL Lines: 56 In article <2668@brl-smoke.ARPA>, moss@BRL.ARPA (Gary S. Moss (SLCBR-VLD-V)) writes: >Bill, > CC prepends an underscore to the function name, and F77 appends >an underscore. So, to call Fortran from C, name the function _forsub in >the Fortran module, invoke it as forsub_ in the C module. You may have >to shorten the name to allow for the extra characters, depending on your >linker. Conversely, define it as forsub_ in the C module, and invoke it >as _forsub in the Fortran module. Be sure to define/invoke the function >from C with pointers (call by reference) exclusively. >-moss. Close but no cigar. Fortran (at least f77 which mostly follows the ANSI standard) doesn't grok '_' in identifiers and even if it did (a la VMS FORTRAN) the above explanation has an error in it. The actual situation might look like this: subroutine forsub(arg1, arg2,...) .... return end main(argc,argv); int argc; char **argv; { void forsub_(); void f_init(); void f_exit(); void exit(); ... /* other declarations */ f_init(); /* a MUST for many UNIX f77's if the subroutines */ /* do I/O; there have been many net inquiries about */ /* this from time to time */ .... forsub_(&arg1, &arg2,...); ... f_exit(); /* flushes, truncates, and closes opened files */ /* among other things; should be done if fortran */ /* I/O was done in the program */ exit(0); } Anyone who has been having trouble interfacing C and f77 can send further questions my way. I am not an expert nor am I involved with f77 or C design but I have had quite a bit of experience with this kind of interface under several different versions of UNIX. UNIX is a registered trademark of AT&T Bell Laboratories. -- ------------------------------- Disclaimer: The views contained herein are | dan levy | yvel nad | my own and are not at all those of my em- | an engihacker @ | ployer or the administrator of any computer | at&t computer systems division | upon which I may hack. | skokie, illinois | -------------------------------- Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa, go for it! allegra,ulysses,vax135}!ttrdc!levy