home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!timbuk.cray.com!walter.cray.com!craywr!wws
- From: wws@craywr.cray.com (Walter Spector)
- Subject: Re: Jumping from nested subroutine
- Message-ID: <1992Nov23.143908.2982@walter.cray.com>
- Lines: 69
- Sender: wws@craywr (Walter Spector)
- Nntp-Posting-Host: craywr.cray.com
- Organization: Cray Research, Inc.
- References: <By4xpo.FG@iapa.uucp%mailhost.ecn.uoknor.edu> <1992Nov23.114807.4734@monu6.cc.monash.edu.au> <By6Ast.BA1@pgroup.com>
- Date: 23 Nov 92 14:39:08 CST
-
- Interesting question.
-
- The much-maligned 'assigned GOTO' is the Standard Fortran version of
- setjmp and longjmp. But assigned GOTO, by the Standard, is limited in
- scope to a single program unit. I've heard that an implementation or two
- accidently support passing what amounts to a LABEL data type down the
- calling chain. Then you can 'GOTO label' where you want to longjmp.
- (I'd be fascinated to know who supports it!)
-
- assign 10 to label
- call suba (label) !! Standard... (see below) !!
- 10 continue
- ...
- end
- subroutine suba (label)
- ...
- goto label !! Non-Standard !!
-
- WARNING: If the above accidently works on your computer, your compiler
- vendor will probably consider it to be a bug. Not a feature.
- If your compiler accidently allows this, and you depend on it,
- comment your code well. Because next time you change compilers or
- port your code to a different machine it WILL break.
-
- In article <By6Ast.BA1@pgroup.com>, lfm@pgroup.com (Larry Meadows) writes:
- |> Well, I can't resist...
- |>
- |> What the original poster wants is called non-local GOTO in pascal, and
- |> setjmp/longjmp in C.
- |> ...
- |> If fortran entry point's don't exist, I'd
- |> be inclined to hack the object to create them.
-
- You would have to be careful when using setjmp in a Fortran
- program. You might write a Fortran-callable glue routine in C
- for setjmp and longjmp. But that glue routine would then have
- present in the calling tree in order to work (I.e., the glue
- routine would then have to call SUBA in the example above).
- A simple setjmp interface would not work since there would be
- no link back to your original routine after a longjmp was taken.
-
- Maybe a LABEL data type is needed in the next rev of the Standard?
- Labels are used in several places - assigned GOTO, alternate RETURN,
- formats, etc. It really isn't wise to overload numeric variable names
- with these labels (shades of Hollerith constants?) IMHO, assigned GOTO
- should not have been depricated in Fortran-90 since sometimes there
- is no alternative. For example, consider the following:
-
- assign 10 to label1
- assign 20 to label2
- call suba (label1,label2) !! Standard
- 10 continue
- ...
- 20 format (10x,8f5.3)
- end
- subroutine suba (label1,label2)
- ...
- write (6,label2) array !! Standard !!
- goto label1 !! Non-Standard !!
-
- In the above, the label is legal for the format, but is illegal for
- a non-local jump. Kind of inconsistent.
-
- Walt
- ----
- Walt Spector
- (wws@renaissance.cray.com)
- Sunnyvale, California
- _._ _._ _.... _. ._.
-