summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/bind_c_dts.f90
blob: f0a31e5408e354837ee7425fffe8be0842f18cb6 (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
! { dg-do run }
! { dg-additional-sources bind_c_dts_driver.c }
module bind_c_dts
  use, intrinsic :: iso_c_binding
  implicit none

  type, bind(c) :: MYFTYPE_1
     integer(c_int) :: i, j
     real(c_float) :: s
  end type MYFTYPE_1

  TYPE, BIND(C) :: particle
     REAL(C_DOUBLE) :: x,vx
     REAL(C_DOUBLE) :: y,vy
     REAL(C_DOUBLE) :: z,vz
     REAL(C_DOUBLE) :: m
  END TYPE particle

  type(myftype_1), bind(c, name="myDerived") :: myDerived

contains
  subroutine types_test(my_particles, num_particles) bind(c)
    integer(c_int), value :: num_particles
    type(particle), dimension(num_particles) :: my_particles
    integer :: i

    ! going to set the particle in the middle of the list
    i = num_particles / 2;
    my_particles(i)%x = my_particles(i)%x + .2d0
    my_particles(i)%vx = my_particles(i)%vx + .2d0
    my_particles(i)%y = my_particles(i)%y + .2d0
    my_particles(i)%vy = my_particles(i)%vy + .2d0
    my_particles(i)%z = my_particles(i)%z + .2d0
    my_particles(i)%vz = my_particles(i)%vz + .2d0
    my_particles(i)%m = my_particles(i)%m + .2d0

    myDerived%i = myDerived%i + 1
    myDerived%j = myDerived%j + 1
    myDerived%s = myDerived%s + 1.0;
  end subroutine types_test
end module bind_c_dts

! { dg-final { cleanup-modules "bind_c_dts" } }