I'm trying to bridge some C code into Fortran. However, I'm having trouble getting the variable length C strings returned by the C API into the fixed length strings required by the Fortran API.
Here's a reduced version of the code that won't compile - I get The shapes of the array expressions do not conform.
character*200 function getValueFromC()
use cbridge
implicit none
type(c_ptr) :: resultString
integer(kind=c_int) :: resultLength
character, pointer, dimension(:) :: string
call c_bridge_getValue(bridge, resultString, resultLength)
call c_f_pointer(resultString, string, (/ resultLength /) )
getValueFromC = string
call c_bridge_releaseString(resultString)
end function getValueFromC
cbridge is just the module containing the c_bridge_getValue() and c_bridge_releaseString definitions, and the bridge pointer (just a void*)
c_bridge_getValue() just mallocs up a new string and returns it, and c_bridge_releaseString() frees the memory.
So my question is, what do I need to do to assign the string variable to the getValueFromC?