Thank you TimP for your reply. It is quite possible that I am just not fluent enough with fortran to explain what I think that code fragment is doing. My intention was to somehow return a valid C pointer to the area of memory set aside by the fortran 'allocate(sdt)' statement. I thought that allocate would automatically 'associate' the 'sdt' fortran pointer with the allocated memory without needing an explicit target?
At any rate, a large amount of our logic is written in Python and/or C and so having an opaque pointer to carry around in the C code allows us to do the higher level logic there and still pass the opaque pointer back and forth to the fortran routines when we need to manipulate the DerivedType data.
In case it clarifies my intentions here is another fragment of fortran code which I was hoping to use to inspect the data structure pointed to by the opaque handle:
subroutine examineDerivedType(this) bind (c, name='examineDerivedType')
use iso_c_binding
type (C_PTR), value :: this
type (SomeDerivedType), pointer :: that
call C_F_POINTER(this, that)
write (*,*) "examineSomeDerivedType_ that%someInteger", that%someInteger
end subroutine
so If this were all working correctly I would expect to be able to use it from C as follows:
[c]
extern void makeSomeDerivedType();
extern void examineSomeDerivedType(void* m);
int main( int argc, const char* argv[] )
{
void* m = makeSomeDerivedType();
examineDerivedType_(m);
}
[/c]
Thank you TimP for your reply. It is quite possible that I am just not fluent enough with fortran to explain what I think that code fragment is doing. My intention was to somehow return a valid C pointer to the area of memory set aside by the fortran 'allocate(sdt)' statement. I thought that allocate would automatically 'associate' the 'sdt' fortran pointer with the allocated memory without needing an explicit target?
At any rate, a large amount of our logic is written in Python and/or C and so having an opaque pointer to carry around in the C code allows us to do the higher level logic there and still pass the opaque pointer back and forth to the fortran routines when we need to manipulate the DerivedType data.
In case it clarifies my intentions here is another fragment of fortran code which I was hoping to use to inspect the data structure pointed to by the opaque handle:
so If this were all working correctly I would expect to be able to use it from C as follows:
[c]
extern void makeSomeDerivedType();
extern void examineSomeDerivedType(void* m);
int main( int argc, const char* argv[] )
{
void* m = makeSomeDerivedType();
examineDerivedType_(m);
}
[/c]