Aleksandar Donev wrote:
> CHARACTER(KIND=C_CHAR,LEN=1024), POINTER :: error_string
> ...
> CALL C_F_POINTER(CPTR=cstr, FPTR=error_string)
This is actually not really legal, since the length of an interoperable
string needs to be 1. Maybe it can be done by using Fortran's sequence
association rules for character strings and arrays, though I am not sure
what the "legal" way to do it is. Maybe the best thing is to just write
the function CStringLength in C and call it from Fortran.
CHARACTER(KIND=C_CHAR), POINTER :: error_string
CALL C_F_POINTER(CPTR=cstr, FPTR=error_string)
CALL C_F_POINTER(CPTR=cstr, FPTR=string, &
SHAPE=[CStringLength(error_string)])
...
CONTAINS
FUNCTION CStringLength(string) RESULT(length)
CHARACTER(C_CHAR), DIMENSION(*) :: string
INTEGER(C_INT) :: length
length=0
DO WHILE(string(length)/=C_NULL_CHAR)
length=length+1
END DO
END FUNCTION
Aleks
|