home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / fortran / 3085 < prev    next >
Encoding:
Text File  |  1992-08-18  |  2.6 KB  |  63 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!convex!convex!patrick
  3. From: Patrick F. McGehearty <patrick@convex.COM>
  4. Subject: Re: summary (was Fortran 90:  Pointers to Functions?)
  5. Originator: patrick@mozart.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Aug18.181240.8613@news.eng.convex.com>
  8. Date: Tue, 18 Aug 1992 18:12:40 GMT
  9. Reply-To: patrick@convex.COM (Patrick F. McGehearty)
  10. References: <16q6bdINNpqh@darkstar.UCSC.EDU>
  11. Nntp-Posting-Host: mozart.convex.com
  12. Organization: Engineering, CONVEX Computer Corp., Richardson, Tx., USA
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 45
  17.  
  18. In article <16q6bdINNpqh@darkstar.UCSC.EDU> sla@fast.ucsc.edu (Steve Allen) writes:
  19. >This is the final summary of all gleaned wisdom on the topic of
  20. >Pointers to Functions in Fortran 90.
  21. ...
  22. >
  23. >Overall this subject has provoked remarkably little response, and I'm
  24. >gonna shut up and keep working on the (Fortran 77) code for my thesis.
  25. ...
  26. There is a way to get the desired functionality using computed goto's.
  27. Determine every possible function that might be assigned to the pointer.
  28. Write a function which is called with the same arguments plus an index.
  29. Store the index in an integer instead of the function in a pointer.
  30.  
  31. I.e.: Assume F1,F2,...,FN might be called.  F? has arguments ARG1,ARG2.
  32. Then:
  33.  
  34.     FUNCTION INDIRECTF(INDEX,ARG1,ARG2)
  35.     IF (INDEX .LT. 0) GO TO 9999
  36. C Assume MAXINDEX set in an appropriate PARAMETER statement
  37.     IF (INDEX .GT. MAXINDEX) GO TO 9999
  38.     GO TO (10,20,...,NN)INDEX
  39. 10    INDIRECTF = F1(ARG1,ARG2)
  40.     RETURN
  41. 20    INDIRECTF = F2(ARG1,ARG2)
  42.     RETURN
  43.     ...
  44. NN    INDIRECTF = FN(ARG1,ARG2)
  45.     RETURN
  46. 9999    ... print appropriate error message ...
  47.     STOP
  48.     END
  49.  
  50. It looks ugly, and the initial setup is tedious, especially compared to
  51. using C function pointers.  It also adds the overhead of an additional
  52. subroutine call.  It has the advantage of forcing all possible callee's to
  53. be identified for later maintainers.  Additional functions can be added
  54. easily, only requiring two lines for the function call, extention of the
  55. computed GOTO, and a change to MAXINDEX.   A file documenting the
  56. correspondence between index and the function should also be maintained.
  57.  
  58. I did something similar using ASSIGNED GOTO's on a CDC6600 many years ago. :-)
  59. While it worked fine for my application, it was not necessarily portable.
  60. Only later did I learn enough about standards and portability to realize
  61. that in many implementations ASSIGNED GOTO's don't work across routine
  62. boundaries.
  63.