[C2hs] Re: [Gtk2hs-users] question on structs with compound members

Axel Simon A.Simon at kent.ac.uk
Thu Oct 23 10:13:59 EDT 2003


On Thu, Oct 23, 2003 at 12:20:01PM +1000, Manuel M. T. Chakravarty wrote:
> > I kinda object to use c2hs for marshalling structures. When I wrote the
> > marshalling code for graphics contexts for gtk+hs, I used c2hs only to
> > find out that it calculates the wrong offsets. 
> 
> That was a bug in c2hs, which has been fixed since then.

Oh, sorry. I thought I'd seen it in the TODO list of c2hs recently - it's 
not there anymore though.

> 
> > Moreover, it is doomed to 
> > produce the wrong offsets in some circumstances with bitfields. Windows 
> > uses a different layout than Unix, even if you use gcc on both platforms. 
> > (gcc behaves differently so that you can use the precompiled Microsoft 
> > libraries).
> 
> Why do you think that c2hs cannot handle this?  If you look
> at the files "c2hs/toplevel/C2HSConfig.hs.in" and
> "c2hs/toplevel/c2hs_config.c" in the c2hs source tree, you
> will see that c2hs actually goes to quite some trouble to
> find out how to properly access bitfields on the particular
> OS and architecture it is running on.  If you have got any
> example, where this does not work properly, please submit it
> as a c2hs bug report.

Ok, I'm wrong there.

BTW, would it be possible that c2hs spits out the platform specific 
versions of types (i.e. Int32 instead of CInt). I think CInt is rather for 
hand-written marshalling code whereas Int32 is more accurate for a 
specific platform. At the moment it's very annoying that hsc2hs and c2hs 
have different opinions as to what C's basic data types map to.


Cheers,
Axel.



More information about the C2hs mailing list