6 ! Based on a contributed code by jwmwalrus@gmail.com
8 ! Before, character(len=:) result variable were rejected in PURE functions.
15 pure function c_strlen(str)
16 character(KIND = C_CHAR), intent(IN) :: str(*)
25 if (str(i) == c_null_char) exit
30 pure function c2fstring(cbuffer) result(string)
31 character(:), allocatable :: string
32 character(KIND = C_CHAR), intent(IN) :: cbuffer(*)
36 string = REPEAT(' ', c_strlen(cbuffer))
38 do i = 1, c_strlen(cbuffer)
39 if (cbuffer(i) == C_NULL_CHAR) exit
40 string(i:i) = cbuffer(i)
48 character(len=:), allocatable :: str
49 str = c2fstring("ABCDEF"//c_null_char//"GHI")
50 if (len(str) /= 6 .or. str /= "ABCDEF") call abort()