aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/c-interop/ff-descriptor-5.f90
blob: e6d17a401cdf1a64f4c7172e1e1c06f40f55be0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
! PR92482
! { dg-do run }
!
! This program checks that passing arrays as assumed-length character
! dummies to and from Fortran functions with C binding works.

program testit
  use iso_c_binding
  implicit none

  character(len=26,kind=C_CHAR) :: aa

  call testc (aa)
  call testf (aa)

contains

  ! C binding version

  subroutine checkc (a) bind (c)
    use iso_c_binding
    character(len=*,kind=C_CHAR) :: a

    if (rank (a) .ne. 0) stop 101
    if (len (a) .ne. 26) stop 102
    if (a .ne. 'abcdefghijklmnopqrstuvwxyz') stop 103
  end subroutine

  ! Fortran binding version
  subroutine checkf (a)
    use iso_c_binding
    character(len=*,kind=C_CHAR) :: a

    if (rank (a) .ne. 0) stop 201
    if (len (a) .ne. 26) stop 202
    if (a .ne. 'abcdefghijklmnopqrstuvwxyz') stop 203
  end subroutine

  ! C binding version
  subroutine testc (a) bind (c)
    use iso_c_binding
    character(len=*,kind=C_CHAR) :: a

    ! Call both the C and Fortran binding check functions
    a = 'abcdefghijklmnopqrstuvwxyz'
    call checkc (a)
    call checkf (a)
  end subroutine

  ! Fortran binding version
  subroutine testf (a)
    use iso_c_binding
    character(len=*,kind=C_CHAR) :: a

    ! Call both the C and Fortran binding check functions
    a = 'abcdefghijklmnopqrstuvwxyz'
    call checkc (a)
    call checkf (a)
  end subroutine

end program