Re: busting sp datatypes
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Thu, 28 Aug 2008 11:28:50 -0800
LR wrote:
(snip)
Just out of curiosity, could you please show me what this would look
like if x was character*7 instead of integer?
Here is a mixed Fortran/C version. I believe that bugs in
g95 0.91 are stopping the all Fortran version from compiling.
(Yes, I should use a newer version.)
use ISO_C_BINDING
interface
subroutine qsort(a,i,n,f) bind(c)
integer,value :: i,n
character*7 a(n)
external f
end subroutine qsort
integer function compare(a,b) bind(c,name="compare")
character*7 a,b
end function compare
end interface
character*7 x(10)
read(*,*) x
! without c_sizeof(), the 7 in the qsort call assumes
! no padding in the array. It works with g95, but I don't
! know if other compilers might add padding.
!
call qsort(x,10,7,compare)
! write(*,*) x
write(*,3) x
3 format(' ''',A7,'''')
end
/* called by qsort from Fortran */
#include <string.h>
int compare(char *a, char *b) {
return strncmp(a,b,7);
}
.
- Follow-Ups:
- Re: busting sp datatypes
- From: Richard Maine
- 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
- From: glen herrmannsfeldt
- Re: busting sp datatypes
- From: LR
- Re: busting sp datatypes
- Prev by Date: Re: Surprise
- 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
|