Difference between hsc2hs and c2hs?

前端 未结 2 1777
逝去的感伤
逝去的感伤 2020-12-24 14:31

What is the difference between hsc2hs and c2hs?

I know what hsc2hs is a preprocessor but what does it exactly do?

And c2hs can make Haskell modules from C-co

2条回答
  •  时光说笑
    2020-12-24 14:44

    Mikhail's answer is good, but there's another side. There are also things that hsc2hs provides that c2hs does not, and it may be necessary to use both in conjunction.

    Notably, hsc2hs operates by producing a C executable that is run to generate Haskell code, while c2hs parses header files directly. Therefore hsc2hs allows you to access #defines, etc. So while I've found c2hs better for generating bindings and wrappers to bindings as well as "deep" peeks and pokes into complex C structures, it is not good for accessing constants and enumerations, and it only automates mildly the boilerplate for Storable instances. I've found hsc2hs necessary as well, in conjunction with the bindings-dsl package [1], in particular in my case for predefined constants. In one instance, I have one hsc file for an enormous amount of constants, and one chs file for wrapping the functions that use these constants.

    [1] http://hackage.haskell.org/package/bindings-DSL

提交回复
热议问题