Clicky

Fortran Wiki
transfer_ex (Rev #1, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #0 to #1: (追記) 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

category: code

Revision from April 27, 2009 22:09:36 by Jason Blevins
Forward in time (to current) | See current | History | Rollback | View: Source | Linked from: Code

AltStyle によって変換されたページ (->オリジナル) /