Re: busting sp datatypes




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);
}


.



Relevant Pages

  • Re: Portability and kind problems
    ... IEEE single is p=6, r=33 or so, ... had naively assumed that compiling with e.g. the -r8 flag produced ... end program test ... But g95 with the first hp option won't compile: ...
    (comp.lang.fortran)
  • Portability and kind problems
    ... had naively assumed that compiling with e.g. the -r8 flag produced ... end program test ... But g95 with the first hp option won't compile: ... This is all on the same machine, so my guess would be that if ifort ...
    (comp.lang.fortran)
  • Re: Enum not found in PNNL FLIB library
    ... The error message you get is more like an internal error of g95, ... I seem to have no problems compiling and ... I'm guessing that either the compilation of flib ...
    (comp.lang.fortran)
  • Re: [PATCH] Fix hid_device_id for cross compiling
    ... Make the padding explicit and consistent across ... architectures. ... It's the well known cross compiling problem with modpost that has bitten ... SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany ...
    (Linux-Kernel)
  • Re: Enum not found in PNNL FLIB library
    ... The error message you get is more like an internal error of g95, ... I seem to have no problems compiling and ... I'm guessing that either the compilation of flib ...
    (comp.lang.fortran)