File: allocatable_component_struct_array_01.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (33 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
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
module pkg_mod
  implicit none

  type :: variant_t
    integer, allocatable :: executable(:)
  end type variant_t

contains

  subroutine temp_func(src)
    type(variant_t), intent(in) :: src
    if (.not. allocated(src%executable)) error stop "expected allocated"
  end subroutine temp_func

end module pkg_mod

program allocatable_component_struct_array_01
  use pkg_mod
  implicit none

  type(variant_t) :: variants_array(2)
  integer :: j

  allocate(variants_array(1)%executable(1))
  variants_array(1)%executable(1) = 1

  call temp_func(variants_array(1))
  if (allocated(variants_array(2)%executable)) error stop "expected unallocated"

  do j = 1, size(variants_array)
     if (allocated(variants_array(j)%executable) .neqv. (j == 1)) error stop "allocation mismatch"
  end do
end program allocatable_component_struct_array_01