Last active
July 3, 2020 11:56
-
-
Save kadircs/f66fa8490dad0f2eaae3cf10c589612f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
integer(kind=c_int) function getstring(instr) bind(C,name='getstring') | |
use, intrinsic :: iso_c_binding | |
character(kind=c_char), dimension(*), intent(IN) :: instr | |
integer :: len | |
integer :: i | |
len=0 | |
do | |
if (instr(len+1) == C_NULL_CHAR) exit | |
len = len + 1 | |
end do | |
print *, 'In Fortran:' | |
print *, 'Got string: ', (instr(i),i=1,len) | |
getstring = len | |
end function getstring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gfortran -c acoustic.f90 | |
gcc -c starsh.c | |
gcc -o bin acoustic.o starsh.o -lgfortran | |
./bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char **argv) { | |
int l; | |
char *name="IGRF"; | |
l = getstring(name); | |
printf("In C: l = %d\n",l); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment