@@ -29,7 +29,15 @@ module opencoarrays
2929#ifdef COMPILER_SUPPORTS_ATOMICS
3030 use iso_fortran_env, only : atomic_int_kind
3131#endif
32- use iso_c_binding, only : c_int,c_char,c_ptr,c_loc,c_double,c_int32_t,c_ptrdiff_t,c_sizeof,c_bool,c_funloc
32+ #if defined(COMPILER_LACKS_C_PTRDIFF_T) || defined(COMPILER_LACKS_C_SIZEOF_ASSUMED_RANK)
33+ use iso_c_binding, only : c_int,c_char,c_ptr,c_loc,c_double,c_int32_t,c_bool,c_funloc,c_long
34+ #elif defined(COMPILER_LACKS_C_PTRDIFF_T)
35+ use iso_c_binding, only : c_int,c_char,c_ptr,c_loc,c_double,c_int32_t,c_bool,c_funloc,c_long ,c_sizeof
36+ #elif defined(COMPILER_LACKS_C_SIZEOF_ASSUMED_RANK)
37+ use iso_c_binding, only : c_int,c_char,c_ptr,c_loc,c_double,c_int32_t,c_bool,c_funloc,c_ptrdiff_t
38+ #else
39+ use iso_c_binding, only : c_int,c_char,c_ptr,c_loc,c_double,c_int32_t,c_bool,c_funloc,c_ptrdiff_t,c_sizeof
40+ #endif
3341 implicit none
3442
3543 private
@@ -52,6 +60,10 @@ module opencoarrays
5260 end type
5361#endif
5462
63+ #ifdef COMPILER_LACKS_C_PTRDIFF_T
64+ integer (c_int), parameter :: c_ptrdiff_t= c_long
65+ #endif
66+
5567 ! Generic interface to co_broadcast with implementations for various types, kinds, and ranks
5668 interface co_reduce
5769 module procedure co_reduce_c_int,co_reduce_c_double,co_reduce_logical
@@ -376,7 +388,6 @@ function gfc_descriptor_c_int(a) result(a_descriptor)
376388 type (gfc_descriptor_t) :: a_descriptor
377389 integer (c_int), parameter :: unit_stride= 1 ,scalar_offset=- 1
378390 integer (c_int) :: i
379-
380391 a_descriptor% dtype = my_dtype(type_= BT_INTEGER,kind_= int (c_sizeof(a)/ bytes_per_word,c_int32_t),rank_= rank(a))
381392 a_descriptor% offset = scalar_offset
382393 a_descriptor% base_addr = c_loc(a) ! data
@@ -385,7 +396,14 @@ function gfc_descriptor_c_int(a) result(a_descriptor)
385396 a_descriptor% dim_(i)% lower_bound = lbound (a,i)
386397 a_descriptor% dim_(i)% ubound_ = ubound (a,i)
387398 end do
388-
399+ #if defined(COMPILER_LACKS_C_SIZEOF_ASSUMED_RANK)
400+ contains
401+ function c_sizeof (mold ) result(c_size_of_mold)
402+ integer (c_int), intent (in ), target :: mold(..)
403+ integer (c_int) :: c_size_of_mold
404+ c_size_of_mold= 4
405+ end function
406+ #endif
389407 end function
390408
391409 function gfc_descriptor_logical (a ) result(a_descriptor)
@@ -420,6 +438,15 @@ function gfc_descriptor_c_double(a) result(a_descriptor)
420438 a_descriptor% dim_(i)% ubound_ = ubound (a,i)
421439 end do
422440
441+ #if defined(COMPILER_LACKS_C_SIZEOF_ASSUMED_RANK)
442+ contains
443+ function c_sizeof (mold ) result(c_size_of_mold)
444+ real (c_double), intent (in ), target :: mold(..)
445+ integer (c_int) :: c_size_of_mold
446+ c_size_of_mold= 4
447+ end function
448+ #endif
449+
423450 end function
424451
425452 ! This version should work for any rank but causes an ICE with gfortran 4.9.2
0 commit comments