home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / apollo / 3893 < prev    next >
Encoding:
Text File  |  1992-11-08  |  2.3 KB  |  58 lines

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