Re: busting sp datatypes
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Wed, 27 Aug 2008 03:36:05 -0800
Ron Ford wrote:
(snip)
qsort is in C's stdlib; can fortran make the necessary interface? I can
think of many ways that this question can be answered in the ngative. I
still don't know what you mean with the word 'interp'.
I think so. You need C_SIZEOF() to pass the appropriate element
size, and you need to be able to pass a comparison function.
The compare function could be written in C, which might be
the easiest way. Otherwise, it is passed (by value) pointers
to two elements to be compared. I believe that could be done
properly with the C interoperability features, including C_FUNPTR
to pass the appropriate function pointer.
Assuming that passing variables to C passes the address,
calling from C passes the pointer by value, which should be
exactly what a Fortran routine would need.
integer compare(i1,i2) bind(c)
compare=0
if(i1>i2) compare=1
if(i1<i2) compare=-1
return
end
external, bind(c) :: compare, qsort
integer x(10)
read(*,*) x
call qsort(x,10,c_sizeof(x(1)),c_funloc(compare))
write(*,*) x
end
-- glen
.
- Follow-Ups:
- Re: busting sp datatypes
- From: LR
- Re: busting sp datatypes
- References:
- Re: busting sp datatypes
- From: glen herrmannsfeldt
- Re: busting sp datatypes
- From: wim
- Re: busting sp datatypes
- From: Ron Ford
- Re: busting sp datatypes
- From: Ron Shepard
- Re: busting sp datatypes
- From: Richard Maine
- Re: busting sp datatypes
- Prev by Date: Re: Using INQUIRE to test if a directory exists
- Next by Date: Re: busting sp datatypes
- Previous by thread: Re: busting sp datatypes
- Next by thread: Re: busting sp datatypes
- Index(es):
Relevant Pages
|