Re: using iso_c_binding
- From: "James Van Buskirk" <not_valid@xxxxxxxxxxx>
- Date: Fri, 14 Mar 2008 09:23:25 -0600
"Brendan" <brendandetracey@xxxxxxxxx> wrote in message
news:a8f7c1c7-d950-44e7-9f09-012510e88695@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks for the indepth replies. I stated in another thread that I do
not know C and have yet to make the leap from 77 to 90/95/2003(got
side-tracked by Matlab), so I am seriously short-handed. I did get
the code to compile with the -m32 flag only to get errors popping out
of the C library to which I am trying to link.
It's a frustration over on this side not to be able to see your current
Fortran code nor the point (compilation, linking, or at runtime) that
you are now experiencing problems, nor the exact error statement...
I guess I better order a copy of 95/2003 explained. I started reading
a 90 text last night...
I have earlier editions of this series (like Fortran 95 Explained)
and they are really good books. At least the earlier editions were
thin enough that you could do a light read of most of the book in
a couple of days after which, although you couldn't possibly get
exact knowledge of all the features of modern Fortran in such a
brief time span, at least you knew roughly what they were and where
to find them in the book.
I just use N1601.pdf for a reference. The chapter on C interop is
short. If you do not know C, you should be aware that it's just an
obfuscated form of PDP-11 assembly and that assembly language is
much easier to learn. I always think about the C interop features
in terms of the machine code that the compiler is producing. With
gfortran and gcc, you can see the machine code by compiling with
the -S switch (this produces an assembly language listing but no
object file or executable) and examining the *.s file the compiler
makes for you. You can synthesize the C procedure you are trying
to link to in Fortran as well:
subroutine Aps_MinMax(A, N, A_MIN, A_MAX) bind(C, NAME='Aps_MinMax')
use ISO_C_BINDING
implicit none
type(C_PTR), value :: A
integer(C_INT), value :: N
type(C_PTR), value :: A_MIN
type(C_PTR), value :: A_MIN
real(C_DOUBLE), pointer :: p_A(:)
real(C_DOUBLE), pointer :: p_A_MIN
real(C_DOUBLE), pointer :: p_A_MAX
call C_F_POINTER(A, p_A, [N])
! You might not want the min
if(C_ASSOCIATED(A_MIN)) then
call C_F_POINTER(A_MIN, p_A_MIN)
p_A_MIN = minval(p_A)
end if
! You might not want the max
if(C_ASSOCIATED(A_MAX)) then
call C_F_POINTER(A_MAX, p_A_MAX)
p_A_MAX = maxval(p_A)
end if
end subroutine Aps_MinMax
This gives you a procedure you can try to link to, but written
in Fortran. I do this a lot and it helps to understand the
issues involved in interfacing to the C procedure.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
.
- References:
- using iso_c_binding
- From: Brendan
- Re: using iso_c_binding
- From: Richard Maine
- Re: using iso_c_binding
- From: FX
- Re: using iso_c_binding
- From: Brendan
- Re: using iso_c_binding
- From: FX
- Re: using iso_c_binding
- From: Brendan
- Re: using iso_c_binding
- From: James Van Buskirk
- Re: using iso_c_binding
- From: Brendan
- using iso_c_binding
- Prev by Date: Re: double precision difference between matlab and fortran 90
- Next by Date: Re: using iso_c_binding
- Previous by thread: Re: using iso_c_binding
- Next by thread: Re: using iso_c_binding
- Index(es):
Relevant Pages
|