home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!agate!darkstar.UCSC.EDU!fast!sla
- From: sla@fast.ucsc.edu (Steve Allen)
- Newsgroups: comp.lang.fortran
- Subject: Re: Fortran 90: Pointers to Functions?
- Date: 14 Aug 1992 17:04:55 GMT
- Organization: UCO/Lick Observatory
- Lines: 59
- Message-ID: <16gp3nINNbm8@darkstar.UCSC.EDU>
- References: <166htnINNhvn@darkstar.UCSC.EDU> <1693l7INNn4o@darkstar.UCSC.EDU>
- NNTP-Posting-Host: fast.ucsc.edu
- Summary: It does not have them, what can be done?
- Keywords: missing feature!
-
- In article <1693l7INNn4o@darkstar.UCSC.EDU> sla@fast.ucsc.edu I wrote:
- >[Fortran 77 & 90 do not have anything like C's "pointer to a function"]
- >Is there some other (reasonably elegant) method for getting this kind of
- >functionality in Fortran 90?
-
- This is an example of what I would like to be doing with pointers to functions
-
- First, the "FORTRAN way", which seems somewhat inelegant
- IF (STATE .EQ. KNOWNSTATE(1)) THEN
- CALL FUNC1
- ELSEIF (STATE .EQ. KNOWNSTATE(2)) THEN
- CALL FUNC2
- C ... about 900 lines of mindless code later ...
- ELSEIF (STATE .EQ. KNOWNSTATE(459)) THEN
- CALL FUNC459
- ELSE
- CALL REPORT_UNKNOWN_STATE(STATE)
- ENDIF
-
- Then, the thing that I would like to be able to do, which can be expressed
- in many fewer lines of code.
- SUCCESS = .FALSE.
- I = 0
- 100 CONTINUE
- IF (.NOT. SUCCESS) THEN
- IF (I .LT. 459) THEN
- I = I + 1
- IF (STATE .EQ. KNOWNSTATE(I)) THEN
- CALL {the Ith function, we have no syntax for this}
- SUCCESS = .TRUE.
- ENDIF
- GOTO 100
- ELSE
- CALL REPORT_UNKNOWN_STATE(STATE)
- ENDIF
- ENDIF
-
- Furthermore, with some kind of array of pointers to functions, I could
- exchange one function in the array for another during the execution of
- the program. Basically, the user pushes some button, and the program
- starts behaving differently because it is calling different functions
- in response to the user's input.
-
- Now for today's questions:
-
- 1)
- Is there some much better way I could do this within Fortran 77 and/or 90?
-
- 2)
- There are lots of good (and bad) examples of complicated user interfaces in C,
- and there are even tools for building user interfaces in C.
- Are there any good examples, reference books, tools for building complicated
- user interfaces in Fortran? (I am hoping for any hints which help the
- programmer to avoid the nearly mindless repetition demonstrated in the
- first example code.)
- _______________________________________________________________________________
- Steve Allen | That was the equation! | sla@helios.ucsc.edu
- UCO/Lick Observatory | Existence!...Survival must | If the UC were opining,
- Santa Cruz, CA 95064 | cancel out programming! -- Ruk | it wouldn't tell me.
-