RECURSIVE vs PURE and ELEMENTAL
Steve Kargl
sgk@troutmask.apl.washington.edu
Sat Aug 4 05:41:00 GMT 2007
On Fri, Aug 03, 2007 at 10:16:38PM -0700, Walter Spector wrote:
> Steve Kargl wrote:
> > ...
> > If I change ELEMENTAL to RECURSIVE in the module. I get a
> > type/rank mismatch, which I think is the correct error.
>
> The legal way to code my test case is that function 'factorial'
> should be ELEMENTAL, and function 'factorial_inner' should be
> PURE RECURSIVE. (Note that since both ELEMENTAL and PURE are
> pure, the Standards do allow one style to call the other.)
>
> The reason I want 'factorial' to be ELEMENTAL, is that in the
> main program I want to be able to call it without regard to
> the rank of the input argument. This is the case in my test
> program, where I write:
>
> results = factorial (vals)
>
> Both 'vals' and 'results' are arrays.
>
OK. If I make the above changes, I get
mobile:kargl[205] gfc4x -o z w1.f90
mobile:kargl[208] ./z 3 4 5
3 6
4 24
5 120
If I remove 'PURE RECURSIVE' from factorial_inner, I get an error
Error: Function reference to 'factorial_inner' at (1) is to a
non-PURE procedure within a PURE procedure
If I remove 'RECURSIVE' in the 'PURE RECURSIVE' from factorial_inner, I get
Error: Function 'factorial_inner' at (1) cannot call itself, as it
is not RECURSIVE
If I change 'PURE RECURSIVE' on factorial_inner to 'ELEMENTAL', I get
the previous error message.
A test with the above combination of changes and gfortran 4.2.0 20070501
also give the expect result (well, to me the expected result).
Another scan of ChangeLog wasn't helpful.
I guess I just don't understand what is failing for you.
--
Steve
More information about the Fortran
mailing list