Commit 3a2afa99 authored by Sergey Kosukhin's avatar Sergey Kosukhin
Browse files

Update m4/acx_check_strptr_convert.m4.

The previous code resulted in the following error when compiled with
GCC 6.4.0 and FCFLAGS=-std=-f2008:

TS 29113/TS 18508: Noninteroperable array FPTR at (1) to C_F_POINTER: Type shall have a character length of 1

Moreover, the code did not really reflect how the string manipulation
was implemented in src/mo_cdi.f90. The updated version is supposed to
be closer to what is required in the real code.
parent 85931dee
......@@ -66,26 +66,24 @@ contains
end function strlen
end interface
type(c_ptr) :: cptr
character(len=:, kind=c_char), pointer :: errstr
character(kind=c_char), dimension(:), pointer :: buf
character(len=:), pointer :: errstr
integer :: i, rv_shape(1)
cptr = strerror(int(errno, c_int))
errstr => c2f_string(cptr, int(strlen(cptr)))
rv_shape(1) = int(strlen(cptr))
call c_f_pointer(cptr, buf, rv_shape)
allocate(character(rv_shape(1)) :: errstr)
do i = 1, rv_shape(1)
errstr(i:i) = buf(i)
end do
end function errstr
function c2f_string(s, slen)
type(c_ptr), intent(in) :: s
integer, intent(in) :: slen
CHARACTER(len=slen, kind=c_char), POINTER :: c2f_string
c2f_string => NULL()
call c_f_pointer(s, c2f_string)
end function c2f_string
end module conftest_mod
program conftest
use iso_c_binding
use conftest_mod, only: errstr
implicit none
character(kind=c_char, len=:), pointer :: msg
character(len=:), pointer :: msg
msg => errstr(42)
write (0, '(a)') msg
end program conftest])],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment