http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110

--- Comment #8 from kargl at gcc dot gnu.org 2011-05-22 18:35:37 UTC ---
I think the subject line is incorrect.  The following testcase
that gets rid of the C interop garbage, works for an input
array of characters with an explicit-shape, but fails with
an assumed-shape array.

program foo

   implicit none

   character s(5)

   s = ['a', 'b', 'c', 'd', 'e']
   print *, bar(s)

   contains

      pure function bar(s) result(a)
!         character, intent(in) :: s(5)       ! Compiles and runs
         character, intent(in) :: s(:)        ! Compiles and segfaults
         character(len=:), allocatable :: a
         integer i
         a = repeat('a', size(s))
         do i = 1, size(s)
            a(i:i) = s(i)
         end do
      end function bar

end program foo

The following workaround allows the original code to compile and
run.


   function c2fstring(cbuffer) result(string)

      character(:), allocatable :: string
      character(KIND = C_CHAR), intent(IN) :: cbuffer(255)

      character(len=255) s
      integer :: i

      s = ''
      do i = 1, SIZE(cbuffer)
         if (cbuffer(i) == C_NULL_CHAR) exit
         s(i:i) = cbuffer(i)
      end do
      string = TRIM(s)

    end function

Reply via email to