recent changes to hsc2hs break wrapping c++

Simon Marlow marlowsd at
Tue Feb 28 11:16:49 CET 2012

On 18/02/2012 05:22, Evan Laforge wrote:
> On Thu, Feb 16, 2012 at 4:27 AM, Simon Marlow<marlowsd at>  wrote:
>> I'm not sure why you're using the C++ compiler from hsc2hs, and I don't
>> think that is guaranteed to work.  But maybe we can fix it if there's a
>> legitimate reason to want it.
> Well, consider if you're writing c++ along with haskell.  You can
> communicate with c++ by passing structs, which are guaranteed to have
> the layout as c, and call functions wrapped in extern "C" {...}.  You
> can't call class constructors from haskell or anything, but you can
> create structs to pass in and use directly in c++, which is already
> quite convenient.
> But those C structs are going to be defined in C++ headers with other
> C++ cruft in them that a C compiler is not going to understand.  But
> if you pass -c g++ to hsc2hs then it works just fine to emit the
> struct offsets.
> Otherwise, I'm not sure how you'd call C++ from the haskell FFI.  Like
> I said, I guess you'd have to split the C structs into separate
> headers, or maybe wall off the C++ bits with ifdefs.  Actually, I
> guess the ifdef part wouldn't be *so* bad, at last as far as ifdeffery
> goes, but it is intrusive on existing headers, which is not going to
> be possible in all situations.  Of course if the C++ API was written
> without regard to the haskell FFI it is likely to require structs to
> be constructed with constructors instead of direct pokes, which is
> beyond the FFI's capabilities.  But in the case where it is designed
> to use plain structs in the haskell-facing bits, it's very convenient
> how you can just pass -c g++ to earlier versions of hsc2hs and have it
> just work.

Ok, I buy that it's useful to be able to do this.  I suggest you make a 
ticket and describe the problem.  Is it possible you'd be able to make a 
patch to fix it too?


More information about the Glasgow-haskell-users mailing list