Clicky
Showing changes from revision #1 to #2:
(追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)
! The transfer intrinsic is Fortran 95's version of a void pointer.
! This program shows how to use transfer to encode a user-defined type
! in a character array.
program transfer_ex
implicit none
! A user-defined data type
type :: data_t
real :: x
end type data_t
! Data to be encoded
type(data_t), target :: d
! Encode data as an array of characters (one byte each)
character(len=1), dimension(:), allocatable :: enc
integer :: length
! Stash our data in d
d%x = 9.d0
print *, 'Data: ', d%x
! Encode the data_t object in a character array
length = size(transfer(d, enc))
allocate(enc(length))
enc = transfer(d, enc)
print *, 'Encoded: ', enc
! Decode again as data_t
d = transfer(enc, d)
print *, 'Decoded: ', d%x
! Clean up
deallocate(enc)
end program transfer_ex
(追記) Also See: (追記ここまで)(追記) happy_new_year (追記ここまで)(追記) (追記ここまで)