Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ucbvax!sdcsvax!sdchem!tps From: tps@sdchem.UUCP Newsgroups: comp.lang.fortran,comp.unix.questions Subject: Re: C subroutine calls from FORTRAN Message-ID: <639@sdchema.sdchem.UUCP> Date: Thu, 19-Feb-87 03:25:19 EST Article-I.D.: sdchema.639 Posted: Thu Feb 19 03:25:19 1987 Date-Received: Fri, 20-Feb-87 02:23:07 EST References: <2324@usceast.UUCP> Sender: news@sdchem.UUCP Reply-To: tps@sdchemf.UUCP (Tom Stockfisch) Organization: UC San Diego Lines: 36 Xref: utgpu comp.lang.fortran:62 comp.unix.questions:1108 In article <2324@usceast.UUCP> still@usceast.UUCP (Bert Still) writes: >When I try to compile and link the following routine (and a few others >which are insignificant for this particular query), I get a bunch of >unresolved external reference messages from the linker. This is apparently >because when you call a routine from f77, an underscore (_) is appended to >the fcn identifier both in front (as cc does) and BEHIND. How does one get >around this problem ? Any ideas would be greatly appreciated. The answer is simple. You can't call C routines directly from fortran unless the latter end in an underscore. THIS IS DEFINITELY A FEATURE. Fortran calls by address, C by value, so 7 times out of 8 you wouldn't want to call the C routine directly. The answer is, for each C routine you want to call, to write a front-end routine in C which the fortran code actually calls, which ends in underscore, and which properly translates to call-by-value. For instance, isatty() has the synopsis isatty( fd ) int fd; Write a front end which (in the C code) you call isatty_(): isatty_( fd ) int *fd; /* a POINTER, which is what fortran passes */ { return isatty( *fd ); } Now in your fortran code you just do integer function isatty() integer ifd, ttyinput ifd = 0 ttyinput = isatty(ifd) || Tom Stockfisch, UCSD Chemistry tps%chem@sdcsvax.UCSD