- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I am trying to call a c function in static library from fortran
on the "c" side the function name is
void set_name(char *s, int *n)
on the fortran side I have created an interface as follows
module f_c_interface
use ISO_C_Binding
interface
subroutine set_name(s,n) bind(C,name="set_name")
character (len=*), intent(inout) :: s
integer , intent(in) :: n
end subroutine set_name
end interface
end module f_c_interface
in the fortran program I have
character (len=128) cname
cname = 'SomeName'
call set_name(cname,len_trim(cname))
on the c side I can see that the length is correct but cname does not pass correctly
Any help would really be appreciated
best
jac
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should use a different declaration for the cname (s) argument in the interface:
character(len=1), intent(inout) :: s(*)
With len=* you instruct the compiler to pass on the length as a hidden argument, one that a Fortran routine would know how to handle but would probably confuse a C function.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page