home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4430 < prev    next >
Encoding:
Text File  |  1992-11-23  |  2.9 KB  |  82 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!timbuk.cray.com!walter.cray.com!craywr!wws
  3. From: wws@craywr.cray.com (Walter Spector)
  4. Subject: Re: Jumping from nested subroutine
  5. Message-ID: <1992Nov23.143908.2982@walter.cray.com>
  6. Lines: 69
  7. Sender: wws@craywr (Walter Spector)
  8. Nntp-Posting-Host: craywr.cray.com
  9. Organization: Cray Research, Inc.
  10. References: <By4xpo.FG@iapa.uucp%mailhost.ecn.uoknor.edu> <1992Nov23.114807.4734@monu6.cc.monash.edu.au> <By6Ast.BA1@pgroup.com>
  11. Date: 23 Nov 92 14:39:08 CST
  12.  
  13. Interesting question.
  14.  
  15. The much-maligned 'assigned GOTO' is the Standard Fortran version of
  16. setjmp and longjmp.  But assigned GOTO, by the Standard, is limited in
  17. scope to a single program unit.  I've heard that an implementation or two
  18. accidently support passing what amounts to a LABEL data type down the
  19. calling chain.  Then you can 'GOTO label' where you want to longjmp.
  20. (I'd be fascinated to know who supports it!)
  21.  
  22.     assign 10 to label
  23.     call suba (label)    !! Standard... (see below) !!
  24.      10    continue
  25.     ...
  26.     end
  27.     subroutine suba (label)
  28.     ...
  29.     goto label        !! Non-Standard !!
  30.  
  31. WARNING: If the above accidently works on your computer, your compiler
  32. vendor will probably consider it to be a bug.  Not a feature.
  33. If your compiler accidently allows this, and you depend on it,
  34. comment your code well.  Because next time you change compilers or
  35. port your code to a different machine it WILL break.
  36.  
  37. In article <By6Ast.BA1@pgroup.com>, lfm@pgroup.com (Larry Meadows) writes:
  38. |> Well, I can't resist...
  39. |> 
  40. |> What the original poster wants is called non-local GOTO in pascal, and
  41. |> setjmp/longjmp in C.
  42. |> ...
  43. |>   If fortran entry point's don't exist, I'd
  44. |> be inclined to hack the object to create them.
  45.  
  46. You would have to be careful when using setjmp in a Fortran
  47. program.  You might write a Fortran-callable glue routine in C
  48. for setjmp and longjmp.  But that glue routine would then have
  49. present in the calling tree in order to work (I.e., the glue
  50. routine would then have to call SUBA in the example above).
  51. A simple setjmp interface would not work since there would be
  52. no link back to your original routine after a longjmp was taken.
  53.  
  54. Maybe a LABEL data type is needed in the next rev of the Standard?
  55. Labels are used in several places - assigned GOTO, alternate RETURN,
  56. formats, etc.  It really isn't wise to overload numeric variable names
  57. with these labels (shades of Hollerith constants?)  IMHO, assigned GOTO
  58. should not have been depricated in Fortran-90 since sometimes there
  59. is no alternative.  For example, consider the following:
  60.  
  61.     assign 10 to label1
  62.     assign 20 to label2
  63.     call suba (label1,label2)    !! Standard
  64.      10 continue
  65.     ...
  66.      20 format (10x,8f5.3)
  67.     end
  68.     subroutine suba (label1,label2)
  69.     ...
  70.     write (6,label2) array        !! Standard !!
  71.     goto label1            !! Non-Standard !!
  72.  
  73. In the above, the label is legal for the format, but is illegal for
  74. a non-local jump.  Kind of inconsistent.
  75.  
  76. Walt
  77. ----
  78. Walt Spector
  79. (wws@renaissance.cray.com)
  80. Sunnyvale, California
  81. _._ _._ _.... _. ._.
  82.