Xref: utzoo comp.lang.c:10348 comp.lang.fortran:686 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!dik From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.lang.c,comp.lang.fortran Subject: Calling C routines from Fortran programs. Message-ID: <7554@boring.cwi.nl> Date: 24 May 88 19:55:18 GMT Organization: CWI, Amsterdam Lines: 39 I know how to call C routines from Fortran programs on the systems I work on. What I want to know is if there are other systems that require other methods. The facts. Given a C routine: foo(a, n) int *a, n; that I want to call from a Fortran program as K = BAR(A, N) What should the interface routine (written in C) look like? The general Unix solution is: bar_(a, n) int *a, *n; { return(foo(a, *n)); } Another interface I have encountered is: BAR(a, n) int *a, *n; { return(foo(a, *n)); } Reading about the cdecl keyword on the net, I suspect tha Microsoft interface ought to be: cdecl int foo(); fortran int bar(a, n) int *a, *n; { return(foo(a, *n)); } (but correct me if I am wrong). And I know one system where I have to write: BAR(a, n) int a, n; { return(foo((int *)(a >> 16), *((int *)(n >> 16)))); } because addresses in Fortran and pointers in C are not aligned the same way. If you know other methods please mail me, I will summarise on the net. -- dik t. winter, cwi, amsterdam, nederland INTERNET : dik@cwi.nl BITNET/EARN: dik@mcvax