Recursive function causes compile-time error

Recursive function causes compile-time error

jfkfcia's picture

Hi,

I have a simple recursive function that causes compilation with ifc to fail. It's as if recursion is not being allowed. The errors reported are:

splinen = ( (x+n/2.)*splinen(x+0.5,n-1) ^ Error 282 at (612:tfed.f) : This is not the name of a function but of a function result * +(n/2.-x)*splinen(x-0.5,n-1))/(n-1) ^ Error 282 at (613:tfed.f) : This is not the name of a function but of a function result



The code compiles fine with PGI and SGI MIPSPro compilers. Here is the function:

RECURSIVE FUNCTION splinen(x,n) REAL x INTEGER n IF(n.eq.1) THEN IF(x.ge.-0.5 .and. x<0.5 ) THEN splinen = 1 ELSE splinen = 0 END IF RETURN ENDIF IF(abs(x)>n/2.) THEN splinen = 0 RETURN ENDIF splinen = ( (x+n/2.)*splinen(x+0.5,n-1) F +(n/2.-x)*splinen(x-0.5,n-1))/(n-1) RETURN END



I don't see any relevant options in the manual, that I am not already using. I am compiling with the flags: -O2 -opt_report -WB -mp -openmp -fpp1 -auto -pc64 -c -cm -w95 -tpp7 -xW.

Thanks for any suggestions,
jfk.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
sburger's picture

You might try writing the function like this:

RECURSIVE FUNCTION splinen(x,n) RESULT(answer)
REAL x
INTEGER n,answer
IF(n.eq.1) THEN
IF(x.ge.-0.5 .and. x<0.5 ) THEN
answer = 1
ELSE
answer = 0
END IF
RETURN
ENDIF
IF(abs(x)>n/2.) THEN
answer = 0
RETURN
ENDIF
answer = ( (x+n/2.)*splinen(x+0.5,n-1)+(n/2.-x)*splinen(x-0.5,n-1))/(n-1)
END FUNCTION splinen

jfkfcia's picture

Obviously I didn't look closely enough at the code to see that the problem was not the recursive call but the variable with the same name as the function :) So your suggestion of course fixed the problem. Many thanks.

Login to leave a comment.