File: class_51.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 (64 lines) | stat: -rw-r--r-- 1,492 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
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
62
63
64
module class_51_mod

   type :: MyType
      integer :: value
   end type MyType

contains

   function my_class_func() result(obj)
      class(MyType), allocatable :: obj
      allocate(obj)
      obj % value = 42
   end function

   function my_type_func() result(obj)
      type(MyType), allocatable :: obj
      allocate(obj)
      obj % value = 37
   end function

   function my_class_func_ptr() result(obj)
      class(MyType), pointer :: obj
      allocate(obj)
      obj % value = 42
   end function

   function my_type_func_ptr() result(obj)
      type(MyType), pointer :: obj
      allocate(obj)
      obj % value = 37
   end function

end module class_51_mod

program class_51
   use class_51_mod
   implicit none

   class(MyType), allocatable :: my_class_var
   class(MyType), pointer :: my_class_var_ptr
   type(MyType), allocatable :: my_type_var
   type(MyType), pointer :: my_type_var_ptr

   my_class_var = my_class_func()

   print *, "my_class_var%value: ", my_class_var%value
   if (my_class_var%value /= 42) error stop

   my_type_var = my_type_func()

   print *, "my_type_var%value: ", my_type_var%value
   if (my_type_var%value /= 37) error stop

   my_class_var_ptr => my_class_func_ptr()

   print *, "my_class_var_ptr%value: ", my_class_var_ptr%value
   if (my_class_var_ptr%value /= 42) error stop

   my_type_var_ptr => my_type_func_ptr()

   print *, "my_type_var_ptr%value: ", my_type_var_ptr%value
   if (my_type_var_ptr%value /= 37) error stop

end program