Hi,
When both a pointer and string are passed from Fortran to C, the strlen argument occupies unexpected place on stack. On Windows, this is fixable by !dec$ attributes (or by -Miface option), but on Linux and Mac OS the order seems to be not under control.
Could you suggest a solution?
Removing the pointer from argument list helps, but this is not an option in my case.
Caller.f90:
program caller
interface
integer function ifoo(p,o,s)
!dec$ attributes c :: ifoo
!dec$ attributes reference :: ifoo
integer, pointer :: p
integer :: o
character(*) :: s
end function ifoo
end interface
integer, target :: n
integer, pointer :: p
character(123) :: s
n = 519
p => n
s = "something"
print *, "calling ifoo, expect ifoo( *:519, *:45, *:[some], 123 )"
i = ifoo(p,45,s)
print *,i,s
end program caller
ifoo.c:
#include <stdio.h>
int ifoo_(int **h, int *i, char *s, int len)
{
printf("ifoo( %p:%d, %p:%d, %p:[%4.4s], %d )\n",
h,**h,i,*i,s,s,len);
fflush(0);
return 0;
}
Using gcc+gfortran I have this output:
calling ifoo, expect ifoo( *:519, *:45, *:[some], *)
ifoo( 0x7fff73e21cc0:519, 0x400c54:45, 0x7fff73e21c40:[some], 123 )
0 something
With PGI C and Fortran 10.8 the output is this:
calling ifoo, expect ifoo( *:519, *:45, *:[some], 123 )
ifoo( 0xfff875f4:519, 0x8075f98:45, 0x807c038:[some], -494084 )
0
something
Thanks
Dima