Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: $Revision: 1.6.2.16 $; site ima.UUCP
Path: utzoo!watmath!clyde!bonnie!akgua!whuxlm!harpo!decvax!cca!ima!johnl
From: johnl@ima.UUCP
Newsgroups: net.lang
Subject: Re: Re: does Fortran 77 allow recursion?
Message-ID: <103600004@ima.UUCP>
Date: Sun, 15-Sep-85 23:09:00 EDT
Article-I.D.: ima.103600004
Posted: Sun Sep 15 23:09:00 1985
Date-Received: Tue, 17-Sep-85 06:19:57 EDT
References: <4152@alice.UUCP>
Lines: 22
Nf-ID: #R:alice:-415200:ima:103600004:000:1140
Nf-From: ima!johnl    Sep 15 23:09:00 1985


As has been pointed out several times here, it is easy to detect at compile
time which routines in a program might be indirectly recursive.
Unfortunately, that is not very useful.  I have seen lots of programs
with routines which call each other back and forth, but are written so that
they are not in fact recursive -- routine A calls routine B which has code
that calls routine A, but not when passed the arguments which A passes to it.
You can't reliably figure this out at compile time since it is clearly
equivalent to the halting problem, which is undecidable.

What you could do, though, and what I have never seen, is to detect recursion
at run time.  Each routine has a flag which it sets when it is entered and
clears when it exits.  Should a routine's flag be set at entry time, it means
that a recursive call is being made and the program can print helpful
diagnostics.

John Levine, ima!johnl

PS:  I must admit, that I wrote a Fortran compiler called INfort which some
of you may have used, and I didn't put in such a check either.  Then again,
since I used the C compiler code generator, recursive routines worked just
fine.