Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Recursion Question

ahasan
Beginner
269 Views
Two verybasic questions:
How are local variables saved in memory for a subroutine with the Recursive keyword?
And , how is the SAVE attribute handled in a subroutine with the recursive keyword?
Thanks for any info!
0 Kudos
5 Replies
Steven_L_Intel1
Employee
269 Views
Variables that don't have the SAVE attribute are allocated on the stack. (Allocatable variables have their descriptors on the stack.) Variables with SAVE are statically allocated. Note that data initialization implies SAVE.
0 Kudos
ahasan
Beginner
269 Views

Is the following correct:

When a subroutine is recursively called (indirectly) another stack is created for the subroutines local variables, and variables that have the SAVE attributemaybe changed during the recursive call. The final value of the SAVEd variable will be the valueafter the last recursive call.

Thanks for the reply.

0 Kudos
Steven_L_Intel1
Employee
269 Views
Close enough.
0 Kudos
ahasan
Beginner
269 Views

Steve:

While searching this Forum for info on stacks, heaps, automatic, recursion, etc. I came across a link to a document that you wrote. Clicking on the link takes me to"Doctor Forum -- Don't Blow Your Stack."However, withinabout 10 secondsthe url is rerouted to an Hp web site, making it impossible to read the document--unless you are a very fast reader. Can you repost the link here?

Thanks.

0 Kudos
Steven_L_Intel1
Employee
269 Views
Better - I'll repost all my Doctor Fortran articles. Stay tuned.
0 Kudos
Reply