home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / fortran / 3039 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  2.6 KB

  1. Path: sparky!uunet!stanford.edu!agate!darkstar.UCSC.EDU!fast!sla
  2. From: sla@fast.ucsc.edu (Steve Allen)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Fortran 90:  Pointers to Functions?
  5. Date: 14 Aug 1992 17:04:55 GMT
  6. Organization: UCO/Lick Observatory
  7. Lines: 59
  8. Message-ID: <16gp3nINNbm8@darkstar.UCSC.EDU>
  9. References: <166htnINNhvn@darkstar.UCSC.EDU> <1693l7INNn4o@darkstar.UCSC.EDU>
  10. NNTP-Posting-Host: fast.ucsc.edu
  11. Summary: It does not have them, what can be done?
  12. Keywords: missing feature!
  13.  
  14. In article <1693l7INNn4o@darkstar.UCSC.EDU> sla@fast.ucsc.edu I wrote:
  15. >[Fortran 77 & 90 do not have anything like C's "pointer to a function"]
  16. >Is there some other (reasonably elegant) method for getting this kind of
  17. >functionality in Fortran 90?
  18.  
  19. This is an example of what I would like to be doing with pointers to functions
  20.  
  21. First, the "FORTRAN way", which seems somewhat inelegant
  22.     IF     (STATE .EQ. KNOWNSTATE(1)) THEN
  23.         CALL FUNC1
  24.     ELSEIF (STATE .EQ. KNOWNSTATE(2)) THEN
  25.         CALL FUNC2
  26. C       ...     about 900 lines of mindless code later ...
  27.     ELSEIF (STATE .EQ. KNOWNSTATE(459)) THEN
  28.         CALL FUNC459
  29.     ELSE
  30.         CALL REPORT_UNKNOWN_STATE(STATE)
  31.     ENDIF
  32.  
  33. Then, the thing that I would like to be able to do, which can be expressed
  34. in many fewer lines of code.
  35.     SUCCESS = .FALSE.
  36.     I = 0
  37. 100     CONTINUE
  38.     IF (.NOT. SUCCESS) THEN
  39.         IF (I .LT. 459) THEN
  40.         I = I + 1
  41.         IF (STATE .EQ. KNOWNSTATE(I)) THEN
  42.             CALL {the Ith function, we have no syntax for this}
  43.             SUCCESS = .TRUE.
  44.         ENDIF
  45.         GOTO 100
  46.         ELSE
  47.         CALL REPORT_UNKNOWN_STATE(STATE)
  48.         ENDIF
  49.     ENDIF
  50.  
  51. Furthermore, with some kind of array of pointers to functions, I could
  52. exchange one function in the array for another during the execution of
  53. the program.  Basically, the user pushes some button, and the program
  54. starts behaving differently because it is calling different functions
  55. in response to the user's input.
  56.  
  57. Now for today's questions:
  58.  
  59. 1)
  60. Is there some much better way I could do this within Fortran 77 and/or 90?
  61.  
  62. 2)
  63. There are lots of good (and bad) examples of complicated user interfaces in C,
  64. and there are even tools for building user interfaces in C.
  65. Are there any good examples, reference books, tools for building complicated
  66. user interfaces in Fortran?  (I am hoping for any hints which help the
  67. programmer to avoid the nearly mindless repetition demonstrated in the
  68. first example code.)
  69. _______________________________________________________________________________
  70. Steve Allen          | That was the equation!         |   sla@helios.ucsc.edu
  71. UCO/Lick Observatory | Existence!...Survival must     | If the UC were opining,
  72. Santa Cruz, CA 95064 | cancel out programming! -- Ruk | it wouldn't tell me.
  73.