Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

More problems with paramterized derived types

$
0
0

This code gives compile errors which I would like help to fix:

module Bar
   implicit none
   integer, parameter :: DP = selected_real_kind(13)

   type VarA(k, n)
      integer, kind :: k
      integer, len :: n
      real(k) :: v
      real(k) :: d(n)
   end type
  
   interface assignment(=)
      module procedure ass_pair
   end interface
  
   contains
  
   pure subroutine ass_pair(b, a)
      type(VarA(DP,*)), intent(in) :: a
      type(VarA(DP,a%n)), intent(inout) :: b
      b%v = a%v
      b%d = a%d
   end subroutine

   pure function max_pair(a, b) result(c)
      type(VarA(DP,*)), intent(in) :: a
      type(VarA(DP,a%n)), intent(in) :: b
      type(VarA(DP,a%n)) c
     
      if (a%v > b%v) then
         c = a
      else
         c = b
      end if
   end function
  
   pure function maxval_array(a) result(b)
      type(VarA(DP,*)), intent(in) :: a(:)
      type(VarA(DP,a%n)) b
      integer i
      b = a(1)
      do i = 2, size(a)
         b = max_pair(a(i), b)
      end do
   end function
  
end module

Source1.f90(31): error #8745: All nondeferred nonassumed type parameters of the dummy argument must have the same values as the corresponding type parameters of the actual argument.   [C]
         c = a
---------^
Source1.f90(33): error #8745: All nondeferred nonassumed type parameters of the dummy argument must have the same values as the corresponding type parameters of the actual argument.   [C]
         c = b
---------^
Source1.f90(41): error #8745: All nondeferred nonassumed type parameters of the dummy argument must have the same values as the corresponding type parameters of the actual argument.   [B]
      b = a(1)
------^
Source1.f90(43): error #8745: All nondeferred nonassumed type parameters of the dummy argument must have the same values as the corresponding type parameters of the actual argument.   [B]
         b = max_pair(a(i), b)
----------------------------^
Source1.f90(43): error #8745: All nondeferred nonassumed type parameters of the dummy argument must have the same values as the corresponding type parameters of the actual argument.   [B]
         b = max_pair(a(i), b)
---------^

This code variant causes internal compiler error but none of the previous errors:

module Bar
   implicit none
   integer, parameter :: DP = selected_real_kind(13)

   type VarA(k, n)
      integer, kind :: k
      integer, len :: n
      real(k) :: v
      real(k) :: d(n)
   end type
  
   interface assignment(=)
      module procedure ass_pair
   end interface
  
   contains
  
   pure subroutine ass_pair(b, a)
      type(VarA(DP,*)), intent(in) :: a
      type(VarA(DP,*)), intent(inout) :: b
      b%v = a%v
      b%d = a%d
   end subroutine

   pure function max_pair(a, b) result(c)
      type(VarA(DP,*)), intent(in) :: a
      type(VarA(DP,*)), intent(in) :: b
      type(VarA(DP,a%n)) c
     
      if (a%v > b%v) then
         c = a
      else
         c = b
      end if
   end function
  
   pure function maxval_array(a) result(b)
      type(VarA(DP,*)), intent(in) :: a(:)
      type(VarA(DP,a%n)) b
      integer i
      b = a(1)
      do i = 2, size(a)
         b = max_pair(a(i), b)
      end do
   end function
  
end module

 


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>