Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Recursive routines - execution order

WSinc
New Contributor I
547 Views

I was wondering if when a recursive routine calls itself, what happens to statements AFTER the call.

Example:

subroutine SUB1(isq)

call sub1(isq+1)

print *,"Does it ever get here?"

print *,isq+1

end

Now if it has a condition such that it SKIPS the call to itself, it will reach the PRINT statement.

But I have seen situations where it got there anyway, and I can't figure out why that would happen.

0 Kudos
2 Replies
WSinc
New Contributor I
547 Views

I meant to say RECURSIVE - sorry.

0 Kudos
Steven_L_Intel1
Employee
547 Views

In your example, no. You will eventually get a stack overflow. A correctly written recursive routine will return when it finds it doesn't need to recurse further.

0 Kudos
Reply