| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Contributed by Jeffrey Hill <[email protected]> |
| 4 |
! |
| 5 |
module associate_ptr |
| 6 |
use iso_c_binding |
| 7 |
contains |
| 8 |
subroutine c_f_strpointer(cptr, ptr2) |
| 9 |
type(c_ptr), target, intent(in) :: cptr |
| 10 |
character(kind=c_char,len=4), pointer :: ptr1 |
| 11 |
character(kind=c_char,len=:), pointer, intent(out) :: ptr2 |
| 12 |
call c_f_pointer(cptr, ptr1) |
| 13 |
if (ptr1 .ne. 'abcd') stop 1 |
| 14 |
ptr2 => ptr1 ! Failed here |
| 15 |
end subroutine |
| 16 |
end module |
| 17 |
|
| 18 |
program test_associate_ptr |
| 19 |
use associate_ptr |
| 20 |
character(kind=c_char, len=1), target :: char_array(7) |
| 21 |
character(kind=c_char,len=:), pointer :: ptr2 |
| 22 |
char_array = ['a', 'b', 'c', 'd', c_null_char, 'e', 'f'] |
| 23 |
! The first argument was providing a constant hidden string length => segfault |
| 24 |
call c_f_strpointer(c_loc(char_array), ptr2) |
| 25 |
if (ptr2 .ne. 'abcd') stop 2 |
| 26 |
end program |