Clicky

Fortran Wiki
transfer_ex (changes)

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

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 (追記ここまで)(追記) (追記ここまで)

category: code

Revised on January 3, 2011 10:59:32 by aerogeek-sukhbinder (207.192.72.34) (908 characters / 0.0 pages)
Edit | Back in time (1 revision) | Hide changes | History | Views: Print | TeX | Source | Linked from: Code

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