File: bindc_06.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 (31 lines) | stat: -rw-r--r-- 892 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
! this tests module variables with bindC are
! correctly assigned in the C file
module bindc_06_mod
   use iso_c_binding, only: c_ptr
   implicit none
   integer, bind(C, name="c_int4") :: f_int4
   logical, bind(C, name="c_logical") :: f_logical
   type(c_ptr), bind(C, name="c_type_c_ptr") :: f_type_c_ptr
   integer(8), bind(C, name="c_int8") :: f_int8
end module

program bindc_06
   use bindc_06_mod
   use iso_c_binding, only: c_f_pointer, c_int
   implicit none
   integer(c_int), pointer :: ptr_f_type_c_ptr

   print *, "f_int4: ", f_int4
   if (f_int4 /= 1) error stop

   print *, "f_int8: ", f_int8
   if (f_int8 /= 2) error stop

   print *, "f_logical: ", f_logical
   if (f_logical .neqv. .false.) error stop

   call c_f_pointer(f_type_c_ptr, ptr_f_type_c_ptr)
   print *, "ptr_f_type_c_ptr: ", ptr_f_type_c_ptr
   if (ptr_f_type_c_ptr /= 12) error stop

end program bindc_06