F
Frank
I successfully did fortran/c interop today. It raised warnings from
gcc.exe but behaved:
F:\gfortran\dan>gcc -c -Wall -Wextra d2.c -I F:\gfortran\include
d2.c: In function 'copy':
d2.c:3: warning: type of 'in' defaults to 'int'
d2.c:3: warning: type of 'out' defaults to 'int'
d2.c:4: warning: passing argument 1 of 'strcpy' makes pointer from integer
witho
ut a cast
d2.c:4: warning: passing argument 2 of 'strcpy' makes pointer from integer
witho
ut a cast
F:\gfortran\dan>gfortran c2.f03 d2.o -Wall -Wextra -o out
F:\gfortran\dan>out
hello world from c
1
2
3
4
5
6
7
8
9
=
☺
♫
hello world
F:\gfortran\dan>type d2.c
#include <string.h>
#include <stdio.h>
void copy(in,out) {
strcpy(out,in);
printf("hello world from c\n");
}
// gcc -c -Wall -Wextra d2.c -I F:\gfortran\include
F:\gfortran\dan>type c2.f03
PROGRAM test
use, intrinsic :: iso_c_binding, only: c_char, c_null_char
implicit none
interface
subroutine copy(in, out) bind(c,name='copy')
use, intrinsic :: iso_c_binding, only: c_char
character(kind=c_char), dimension(*) :: in, out
end subroutine copy
end interface
character(len=20, kind=c_char) :: &
digit_string = c_char_'123456789' // c_null_char
character(kind=c_char) :: digit_arr(20)
call copy(digit_string, digit_arr)
print '(1x, a1)', digit_arr(1:19)
print *, "hello world"
END PROGRAM test
! gfortran c2.f03 d2.o -Wall -Wextra -o out
F:\gfortran\dan>
I could add casts to see if the warnings would disappear, but I'd like to
know *why* I'm adding a cast before I do so.
Fishing for tips. Cheers,
--
Frank
I once asked the most fabulous couple I know, Madonna and Guy Ritchie, how
they kept things fresh despite having been married for almost seven months.
'It's a job, Al,' Guy told me. 'We work at it every day.'
~~ Al Franken,
gcc.exe but behaved:
F:\gfortran\dan>gcc -c -Wall -Wextra d2.c -I F:\gfortran\include
d2.c: In function 'copy':
d2.c:3: warning: type of 'in' defaults to 'int'
d2.c:3: warning: type of 'out' defaults to 'int'
d2.c:4: warning: passing argument 1 of 'strcpy' makes pointer from integer
witho
ut a cast
d2.c:4: warning: passing argument 2 of 'strcpy' makes pointer from integer
witho
ut a cast
F:\gfortran\dan>gfortran c2.f03 d2.o -Wall -Wextra -o out
F:\gfortran\dan>out
hello world from c
1
2
3
4
5
6
7
8
9
=
☺
♫
hello world
F:\gfortran\dan>type d2.c
#include <string.h>
#include <stdio.h>
void copy(in,out) {
strcpy(out,in);
printf("hello world from c\n");
}
// gcc -c -Wall -Wextra d2.c -I F:\gfortran\include
F:\gfortran\dan>type c2.f03
PROGRAM test
use, intrinsic :: iso_c_binding, only: c_char, c_null_char
implicit none
interface
subroutine copy(in, out) bind(c,name='copy')
use, intrinsic :: iso_c_binding, only: c_char
character(kind=c_char), dimension(*) :: in, out
end subroutine copy
end interface
character(len=20, kind=c_char) :: &
digit_string = c_char_'123456789' // c_null_char
character(kind=c_char) :: digit_arr(20)
call copy(digit_string, digit_arr)
print '(1x, a1)', digit_arr(1:19)
print *, "hello world"
END PROGRAM test
! gfortran c2.f03 d2.o -Wall -Wextra -o out
F:\gfortran\dan>
I could add casts to see if the warnings would disappear, but I'd like to
know *why* I'm adding a cast before I do so.
Fishing for tips. Cheers,
--
Frank
I once asked the most fabulous couple I know, Madonna and Guy Ritchie, how
they kept things fresh despite having been married for almost seven months.
'It's a job, Al,' Guy told me. 'We work at it every day.'
~~ Al Franken,