- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to demonstrate that an AUTOMATIC variable do not retain its value upon re-entry into a subroutine. The following sample DOES retain 'x' value which prints as 1.000000upon the 2nd entry into 'sub'. How can I demonstrate AUTOMATIC vs. SAVE attribute with a simple program?
call subcall sub
end
subroutine sub
real, automatic :: x
print *,x
x=1.
end
Thanks,
Yair
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The automatic storage is not purged upon leaving sub. It is available for re-use. If you call another subroutine between, setting different values on the stack, you may find the data have been over-written.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your hint did make the following new sample prove the point.
Now x shows as 5.8832619E-39 on the 2nd entry into sub1.
Thanks a lot,
Yair
call sub1call sub2
call sub1
end
subroutine sub1
real, automatic :: x
print *,x
x=1.
end
subroutine sub2
real, automatic :: y(200000)
y=2.
end

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page