home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.apollo
- Path: sparky!uunet!mcsun!dxcern!vxcrna.cern.ch!roeber
- From: roeber@vxcrna.cern.ch
- Subject: Re: Passing C/Fortran routines as Arguments
- Message-ID: <1992Nov8.122452.1@vxcrna.cern.ch>
- Sender: news@dxcern.cern.ch (USENET News System)
- Reply-To: roeber@cern.ch
- Organization: CERN -- European Organization for Nuclear Research
- References: <1992Nov7.133608.12214@dxcern.cern.ch>
- Date: Sun, 8 Nov 1992 11:24:52 GMT
- Lines: 45
-
- In article <1992Nov7.133608.12214@dxcern.cern.ch>, burow@dxcern.cern.ch (Burkhard Burow) writes:
- >
- > I'd like to pass routines as arguments between C and Fortran, but don't seem to
- > be able to find any documentation on it in the Domain C (or Fortran) Language
- > Reference.
- >
- > e.g.
- > cm.c: void a_() {return;} fm.f: subroutine a
- > return
- > end
- >
- > main() { b_(a_); } external a,b
- > call b(a)
- > end
- >
- > c.c: void b_(void f()) {f();} f.f: subroutine b(f)
- > external f
- > call f
- > return
- > end
-
- You need one more level of indirection to make the Fortran happy:
- cm.c: void a_() {return;}
- static void (*ap)() = a_; /* pointer to the function */
-
- main() { b_(&ap); } /* passing a pointer-to-pointer-to-fn */
-
- c.c: void b_(void (**f)()) {(**f)();}
-
- In cm.c you can't just go "main(){b_(&a_);}," because the c compiler
- treats &a_ as the same as a_. That's also why you need two splats
- each in c.c.
-
- Also, look into receiving parameters with the "&" qualifier, this
- is an extension borrowed from C++ which specifies that the parameter
- is implicitly passed by reference, like Fortran and Pascal. Most
- of the Apollo system calls are prototyped with it.
-
- --
- Frederick G. M. Roeber | CERN -- European Center for Nuclear Research
- e-mail: roeber@cern.ch or roeber@caltech.edu | work: +41 22 767 31 80
- r-mail: CERN/PPE, 1211 Geneva 23, Switzerland | home: +33 50 42 19 44
- --
- % stcode 1D01001E
- Vendor "Apollo" can not be deleted (network license server/server)
-