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

Saving an ALLOCATABLE array

tlillys
Beginner
1,065 Views
I was hoping to allocate an array in a dll and pass it back to the calling VB code. From browsing the docs, a locally allocated array is deallocated when the sub/func is exited, either by default or by DEALLOCATE. The SAVE attribute conflicts with the ALLOCATABLE attribute.

It appears that I cannot do what I want. Is this true, or have I missed something?

My work around is to write another function to determine the size, dimension it in VB and pass the first element of the array and its dimension.

Thanks for any remarks.
Ted
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
1,065 Views
SAVE attribute does not conflict with ALLOCATABLE. It's perfectly OK and standard to declare an array ALLOCATABLE,SAVE. The problem might be if VB unloads your dll in the meantime -- I don't think it does it, so you might give it a try.

However, (out of curiosity, I'm not familiar with VB), how do you mean to "pass it" to VB code? That implies that VB is able to dereference it via a C-style pointer -- I don't recall if it can do it (note that even standard Fortran-95 cannot have ALLOCATABLE arguments). OTOH, that method would require separate routines (or additional argument in the call) to allocate/deallocate arrays.

...I must admit I like your "workaround" more -- that interface is cleaner.

Jugoslav
0 Kudos
Reply