program main
implicit none
integer(4),parameter:: lp = 4_4, ip = 4_4
integer(4):: i,j
i = 52793874
j = i
print*, anyiseq(i,j)
print*, anyiseq2(i,j)
contains
!--compare two scalar byte by byte
elemental logical(lp) function anyiseq(lhs,rhs) result(r)
class(*),intent(in):: lhs,rhs
integer(1),dimension(sizeof(lhs)):: lb
integer(1),dimension(sizeof(rhs)):: rb
integer(ip):: i
r = .false.
if(.not.same_type_as(lhs,rhs)) return
if(.not.size(lb)==size(rb)) return
lb = transfer(lhs,mold=lb)
rb = transfer(rhs,mold=rb)
r = all(lb==rb)
end function anyiseq
!--compare two scalar byte by byte
logical(lp) function anyiseq2(lhs,rhs) result(r)
class(*),intent(in):: lhs,rhs
character(len=sizeof(lhs),kind=1):: lb
character(len=sizeof(rhs),kind=1):: rb
integer(ip):: i
r = .false.
if(.not.same_type_as(lhs,rhs)) return
if(.not.len(lb)==len(rb)) return
lb = transfer(lhs,mold=lb)
rb = transfer(rhs,mold=rb)
r = lb == rb
end function anyiseq2
end program main
here i compare two unlimited polymorphism types byte by byte
i tested two methods with debug mode, and i received <access violation> for the second one at line
lb = transfer(lhs,mold=lb)
is this a bug or i missed something?
i use the vs2015+ifort2017u4
and more
for now, i just have tested this function for some simple derived type.
i wonder anyone have experience about this method and knows whether it's a proper way to compare any types