Xref: utzoo comp.lang.c:39483 comp.lang.fortran:5465 comp.unix.questions:31554 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!sdrc!wggabb From: wggabb@sdrc.COM (Rob Gabbard) Newsgroups: comp.lang.c,comp.lang.fortran,comp.unix.questions Subject: Re: Calling C from FORTRAN under Unix Message-ID: <947@sdrc.COM> Date: 22 May 91 18:44:20 GMT References: <5343@dftsrv.gsfc.nasa.gov> Followup-To: comp.lang.c Organization: SDRC, Cincinnati Lines: 41 From article <5343@dftsrv.gsfc.nasa.gov>, by packer@amarna.gsfc.nasa.gov (Charles Packer): > On a Unix system I want to call a C routine from a FORTRAN > program. The linker says the C routine is undefined. On a VMS > system, the problem doesn't happen. The reason why there is a > problem on a Unix system has something to do with the name of > the C subroutine acquiring a preceding underscore ("_") during > compilation, or some such nonsense. To anyone familiar with this > problem: what is the way around it? Try declaring your C routine as routinename_ We get around this by having a host dependent include file with a special macro in it used in our C function definitions like this: In the include file (e.g. portable.h): For an "underscore" machine.... #define IDENTITY(x) x #define FORTRAN_CALLABLE(x) void IDENTITY(x)_ For a "non-underscore" machine.... #define FORTRAN_CALLABLE(x) void x Example C funtion definition: #include "/wherever.../portable.h" FORTRAN_CALLABLE(routine)(int foo, char *fubar) The IDENTITY macro is a kludge to get around the fact that x_ doesn't work. The void is there to keep our programmers from designing any C functions that return values like Fortran functions. Since there is no defined standard for this we don't allow it. In all systems I've seen returning an int works but you never know. -- The statements above are my own and do not neccesarily reflect the opinion of my employer. ------------------------------------------------------------------------------- Rob Gabbard wggabb@sdrc.sdrc.com Technical Development Engineer Structural Dynamics Research Corporation