No automatic support for marshaling of structures?

Hi All, When I was trying to marshal a C structure in Haskell, I met such error: "Illegal structure or union type! There is no automatic support for marshaling of structures and unions". However, if I try to marshal the pointer to a structure, it works well. Could anyone give me any hints? Thank you! The structure I define in C is: ------------- typedef point{ int x,y; }; -------------- And the marshaling code in C2HS is: -------------- newtype Point = Point {#type point#} -------------- Best wishes, Jun Direct: +46 8 790 4150 Fax: +46 8 751 1793 Post Address: KTH/IMIT/ LECS, Electrum 229, SE-164 40 Kista, Sweden Visiting address: Forum-Building, Isafjordsgatan 39, 8th floor, elevator C

Hi Jun,
When I was trying to marshal a C structure in Haskell, I met such error: "Illegal structure or union type! There is no automatic support for marshaling of structures and unions". However, if I try to marshal the pointer to a structure, it works well.
As the error message says there is no automatic facility for marshalling structs and unions - in fact, there is no one best way to do it. The easiest solution is to define a Haskell version of your C structure
The structure I define in C is: ------------- typedef point{ int x,y; }; --------------
So, you would define data Point = Point {x :: Int, y :: Int} Then, define an instance of the type class Storable for Point. (Storable is a class from the FFI addendum, see the GHC Haddock documentation for details.) Afterwards you can use c2hs get and set hooks to marshal between the C and the Haskell representation. Manuel
participants (2)
-
Manuel M T Chakravarty
-
zhu Jun