- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What does the declaration of a function look like that returns a c_ptr?
Link Copied
- « Previous
-
- 1
- 2
- Next »
23 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. One would think so. I tried it and it always returned false.
Sadly, this 'works'
[fortran]!DEC$ ATTRIBUTES DLLEXPORT,DECORATE,ALIAS:'del_array3' :: del_array3 integer function del_array3(cptr0, ilen) bind(c,name='del_array3') type(c_ptr),intent(inout) :: cptr0 type(c_ptr):: cptr1 integer, intent(in) :: ilen integer(1), dimension(:),pointer :: fptr0 integer :: i0 =-1,i1=-1 integer :: indx = 1 integer :: iout = -1 logical :: bstatus =.true. !call C_F_POINTER(cptr0,fptr0,[ilen]) i0 = transfer (cptr0, i0) FIND_FINDX: do indx = 1, 256,1 if (apfi1(indx)%istate == 1) then cptr1 = C_LOC(apfi1(indx)%pf_ab) !bstatus = associated(apfi1(indx)%pf_ab, fptr0) i1 = transfer (cptr1, i1) if(i1 == i0) then deallocate(apfi1(indx)%pf_ab) apfi1(indx)%istate = -1 iout = indx exit FIND_FINDX endif endif enddo FIND_FINDX del_array3 = iout end function del_array3[/fortran]
Sadly, this 'works'
[fortran]!DEC$ ATTRIBUTES DLLEXPORT,DECORATE,ALIAS:'del_array3' :: del_array3 integer function del_array3(cptr0, ilen) bind(c,name='del_array3') type(c_ptr),intent(inout) :: cptr0 type(c_ptr):: cptr1 integer, intent(in) :: ilen integer(1), dimension(:),pointer :: fptr0 integer :: i0 =-1,i1=-1 integer :: indx = 1 integer :: iout = -1 logical :: bstatus =.true. !call C_F_POINTER(cptr0,fptr0,[ilen]) i0 = transfer (cptr0, i0) FIND_FINDX: do indx = 1, 256,1 if (apfi1(indx)%istate == 1) then cptr1 = C_LOC(apfi1(indx)%pf_ab) !bstatus = associated(apfi1(indx)%pf_ab, fptr0) i1 = transfer (cptr1, i1) if(i1 == i0) then deallocate(apfi1(indx)%pf_ab) apfi1(indx)%istate = -1 iout = indx exit FIND_FINDX endif endif enddo FIND_FINDX del_array3 = iout end function del_array3[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"Working" complete code and files attached. I have older 10.0.25 fortran version, but all the interlocked comments come with a new question about easy ways to accomplish an InterlockedAdd Function or InterlockedIncrement. I think the OpenMP critical and atomic may suffice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The easy way to interface Fortran and C is to use the ISO C Binding. See the link below

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
- « Previous
-
- 1
- 2
- Next »