forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ISO_C_BINDING

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
StamK



Joined: 12 Oct 2016
Posts: 145

PostPosted: Wed Jun 02, 2021 2:09 pm    Post subject: ISO_C_BINDING Reply with quote

Is this implemented fully?

For example C_F_POINTER doesn't seem to be recognised.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7142
Location: Salford, UK

PostPosted: Wed Jun 02, 2021 5:41 pm    Post subject: Reply with quote

StamK

Fortran 2003 ISO_C_BINDING is implemented except for the intrinsics C_ASSOCIATED, C_F_POINTER and C_F_PROCPOINTER.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7142
Location: Salford, UK

PostPosted: Thu Jun 03, 2021 7:21 am    Post subject: Reply with quote

StamK

Do you have code that uses C_F_POINTER. Can you post a sample?
Back to top
View user's profile Send private message AIM Address
StamK



Joined: 12 Oct 2016
Posts: 145

PostPosted: Sat Jun 19, 2021 12:59 am    Post subject: Reply with quote

Sorry, somehow didn't get a notification of your reply.
The code is the one in the accepted answer
https://stackoverflow.com/questions/19147743/passing-allocatable-array-from-fortran-to-c-and-malloc-it
Was trying to use malloc/free directly since we are having problems with get_storage@ etc.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7142
Location: Salford, UK

PostPosted: Sat Jun 19, 2021 7:42 am    Post subject: Reply with quote

StamK

If you are using only FTN95 then there will probably be a fix that we could provide. Alternatively we may be able to implement C_F_POINTER for you.

Either way we would need some sample code that illustrates what you want to do.
Back to top
View user's profile Send private message AIM Address
StamK



Joined: 12 Oct 2016
Posts: 145

PostPosted: Sun Jun 20, 2021 12:06 pm    Post subject: Reply with quote

We just want to develop our own malloc/free Fortran calls, and iso_c_binding allows to use the C pointers seamlessly. In any case C_F_POINTER is a very important element of iso_c_binding so it is important to get it to work.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7142
Location: Salford, UK

PostPosted: Sun Jun 20, 2021 12:34 pm    Post subject: Reply with quote

StamK

Can you post some code that illustrates how C_F_POINTER is used.
Back to top
View user's profile Send private message AIM Address
StamK



Joined: 12 Oct 2016
Posts: 145

PostPosted: Sun Jun 20, 2021 1:00 pm    Post subject: Reply with quote

Courtesy of https://stackoverflow.com/questions/19147743/passing-allocatable-array-from-fortran-to-c-and-malloc-it

Code:

#include "stdlib.h"
int *create_storage()
{
   /* Array of four integers. */
   return malloc(sizeof(int) * 4);
}

void destroy_storage(int *ptr)
{
   free(ptr);
}


PROGRAM fortran_side
  USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR, C_F_POINTER, C_INT
  IMPLICIT NONE
  INTERFACE
    FUNCTION create_storage() BIND(C, NAME='create_storage')
      USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR
      IMPLICIT NONE
      TYPE(C_PTR) :: create_storage
    END FUNCTION create_storage
    SUBROUTINE destroy_storage(p) BIND(C, NAME='destroy_storage')
      USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR
      IMPLICIT NONE
      TYPE(C_PTR), INTENT(IN), VALUE :: p
    END SUBROUTINE destroy_storage
  END INTERFACE
  TYPE(C_PTR) :: p
  INTEGER(C_INT), POINTER :: array(:)
  !****
  p = create_storage()
  CALL C_F_POINTER(p, array, [4])   ! 4 is the array size.
  ! Work with array...
  CALL destroy_storage(p)
END PROGRAM fortran_side
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7142
Location: Salford, UK

PostPosted: Mon Jun 21, 2021 10:01 am    Post subject: Reply with quote

StamK

This code suggests to me that C_F_POINTER is equivalent to the FTN95 extension of using ABSOLUTE_ADDRESS with ALLOCATE...

ALLOCATE(array(4), ABSOLUTE_ADDRESS=p)

but I wonder why you would want to do this rather than simply call ALLOCATE(array(4)).

Also if GET_STORAGE@ does not work for you then we should look into that.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7142
Location: Salford, UK

PostPosted: Mon Jun 28, 2021 10:19 am    Post subject: Reply with quote

StamK

In the next release of the FTN95 library, the 64 bit definition of GET_STORAGE@ has been improved. You have reported that GET_STORAGE@ was not working for you and this change may make a difference.

This change will be in the next release of the DLLs.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group