aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/bind_c_usage_24.f90
blob: a46772be249619eb652a1bfe7ea3cad80dc10fa3 (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
! { dg-do run }
! { dg-additional-sources bind_c_usage_24_c.c }
!
! PR fortran/48858
! PR fortran/48820
!
! TS 29113: BIND(C) with OPTIONAL
!
module m
  use iso_c_binding
  interface
    subroutine c_proc (is_present, var) bind(C)
      import
      logical(c_bool), value    :: is_present
      integer(c_int),  optional :: var
    end subroutine
  end interface
contains
  subroutine subtest (is_present, var) bind(C)
    logical(c_bool), intent(in),    value    :: is_present
    integer(c_int),  intent(inout), optional :: var
    if (is_present) then
      if (.not. present (var)) call abort ()
      if (var /= 43) call abort ()
      var = -45
    else
      if (present (var)) call abort ()
    end if
  end subroutine subtest
end module m

program test
  use m
  implicit none
  integer :: val

  val = 4
  call c_proc (.false._c_bool)
  call c_proc (.true._c_bool, val)
  if (val /= 7) call abort ()
end program test