On Wed, 13 Apr 2011, Nabil Alsharif wrote:

instance Storable myUnion where
   size _ = #{size my_union} -- <-- hsc2hs shortcut
alignment _ = alignment undefined::CInt -- <-- What should this really be?
   peek ptr = do -- <-- How are you supposed to know which element to extract?

That's the great "feature" of C unions, that you cannot know that in general. You have to store somewhere else, in a boolean or flag set, whether the stored union value contains a 'char' or an 'int'.

   poke ptr (I i) =  poke ptr i -- <-- Or should this be #{poke my_union, i}  
ptr i ?
   poke ptr (C c) = poke ptr c

_______________________________________________
FFI mailing list
FFI@haskell.org
http://www.haskell.org/mailman/listinfo/ffi

Reply via email to