Structure handles (C interopability)

eos pengwern
Total Points:
1,955
Status Points:
1,455
Brown Belt
July 8, 2009 2:26 AM PDT
Rate
 
#2 Reply to #1
Quoting - tim18
According to Fortran 95 standard, allocatable arrays/objects are deallocated automatically at subroutine exit, when they go out of scope.  For the previous 5 years, it was necessary to deallocate explicitly.  You are entitled to deallocate explicitly if you wish.  The Fortran system is entitled also to deallocate other local variables which don't have SAVE declarations, as a C compiler would do with auto variables.
If you had SAVE variables and called multiple concurrent instances of the subroutine, you would have a storage clash, analogous to C static variables.


So I guess that in this case, as the pointer that has been allocated resides in the module rather than in the 'initialize' subroutine, it stays allocated until explicitly deallocated just like an allocatable array would if held in the module.

Presumably, the fact that 'struct' is a pointer, and there is no static variable of type(pass) defined, is the mechanism that lets the compiler avoid overwriting the same 'struct' over and over again. I haven't used pointers like this before; normally I create a bunch of allocatable arrays, and create a pointer to point at one of them. If I then try to allocate an array that has already been allocated, I get an 'already allocated' error message. The concept of being able to allocate multiple structures with the same name but different pointers is unfamiliar, but I can see its very powerful.

Stephen.



Intel Software Network Forums Statistics

8491 users have contributed to 31629 threads and 100767 posts to date.
In the past 24 hours, we have 30 new thread(s) 136 new posts(s), and 192 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to Crash when loading skeleton The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member shadowwolf99