[Fortran] 纯文本查看 复制代码
program main
implicit none
Integer :: a
Real :: b
a = 3
b = 1.0
write(*,'("0x",z8.8)') a
call CnvrtEndian( a , 4 )
write(*,'("0x",z8.8)') a
write(*,'("0x",z8.8)') b
call CnvrtEndian( b , 4 )
write(*,'("0x",z8.8)') b
contains
Subroutine CnvrtEndian( byteIn , nByte )
use , intrinsic :: ISO_C_Binding
class(*) , target , Intent(INOUT) :: byteIn
integer , Intent(IN) :: nByte
character , pointer :: p(:)
call c_f_pointer( c_loc(byteIn) , p , [nByte] )
p = p(nByte:1:-1)
End Subroutine CnvrtEndian
end program main
[Fortran] 纯文本查看 复制代码
program main
implicit none
integer,target::a=3
real,target::b=8.15
class(*),pointer::p
ALLOCATE(p,source=a) !f2018标准支持 p=a
call write_p(p)
p=>b
call write_p(p)
ALLOCATE(p,source=b) !f2018标准支持 p=b
call write_p(p)
p=>a
call write_p(p)
contains
subroutine write_p(p)
class(*),pointer,intent(in)::p
select type(p)
type is(integer)
write(*,"(I3)")p
type is(real)
write(*,"(F8.2)")p
end select
end subroutine write_p
end program