| 1 |
! PR92482 |
| 2 |
! { dg-do run } |
| 3 |
! |
| 4 |
! This program checks that passing arrays as assumed-length character |
| 5 |
! dummies to and from Fortran functions with C binding works. |
| 6 |
|
| 7 |
program testit |
| 8 |
use iso_c_binding |
| 9 |
implicit none |
| 10 |
|
| 11 |
character(len=26,kind=C_CHAR) :: aa |
| 12 |
|
| 13 |
call testc (aa) |
| 14 |
call testf (aa) |
| 15 |
|
| 16 |
contains |
| 17 |
|
| 18 |
! C binding version |
| 19 |
|
| 20 |
subroutine checkc (a) bind (c) |
| 21 |
use iso_c_binding |
| 22 |
character(len=*,kind=C_CHAR) :: a |
| 23 |
|
| 24 |
if (rank (a) .ne. 0) stop 101 |
| 25 |
if (len (a) .ne. 26) stop 102 |
| 26 |
if (a .ne. 'abcdefghijklmnopqrstuvwxyz') stop 103 |
| 27 |
end subroutine |
| 28 |
|
| 29 |
! Fortran binding version |
| 30 |
subroutine checkf (a) |
| 31 |
use iso_c_binding |
| 32 |
character(len=*,kind=C_CHAR) :: a |
| 33 |
|
| 34 |
if (rank (a) .ne. 0) stop 201 |
| 35 |
if (len (a) .ne. 26) stop 202 |
| 36 |
if (a .ne. 'abcdefghijklmnopqrstuvwxyz') stop 203 |
| 37 |
end subroutine |
| 38 |
|
| 39 |
! C binding version |
| 40 |
subroutine testc (a) bind (c) |
| 41 |
use iso_c_binding |
| 42 |
character(len=*,kind=C_CHAR) :: a |
| 43 |
|
| 44 |
! Call both the C and Fortran binding check functions |
| 45 |
a = 'abcdefghijklmnopqrstuvwxyz' |
| 46 |
call checkc (a) |
| 47 |
call checkf (a) |
| 48 |
end subroutine |
| 49 |
|
| 50 |
! Fortran binding version |
| 51 |
subroutine testf (a) |
| 52 |
use iso_c_binding |
| 53 |
character(len=*,kind=C_CHAR) :: a |
| 54 |
|
| 55 |
! Call both the C and Fortran binding check functions |
| 56 |
a = 'abcdefghijklmnopqrstuvwxyz' |
| 57 |
call checkc (a) |
| 58 |
call checkf (a) |
| 59 |
end subroutine |
| 60 |
|
| 61 |
end program |