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

Recursion Question

ahasan
초급자
603 조회수
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 포인트
5 응답
Steven_L_Intel1
603 조회수
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 포인트
ahasan
초급자
603 조회수

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 포인트
Steven_L_Intel1
603 조회수
Close enough.
0 포인트
ahasan
초급자
603 조회수

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 포인트
Steven_L_Intel1
603 조회수
Better - I'll repost all my Doctor Fortran articles. Stay tuned.
0 포인트
응답