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