
Axel Simon
I am trying to use the conditional compilation feature of the latest release of c2hs. My code looks something like this:
#include
#if GTK_CHECK_VERSION(2,2,0)
treeStoreRemove :: (TreeStoreClass ts) => ts -> TreeIter -> IO Bool treeStoreRemove ts ti = liftM toBool $ {#call tree_store_remove#} (toTreeStore ts) ti
#else
treeStoreRemove :: (TreeStoreClass ts) => ts -> TreeIter -> IO () treeStoreRemove ts ti = {#call tree_store_remove#} (toTreeStore ts) ti
#endif
First of all there is a but that a newline in front of each # is lost so that cpp conditionals wind up on the line above (which was of course a comment, so passed unnoticed...).
You mean that c2hs drops the newline in front of each cpp directive?
But more important is that the test yields true but c2hs compiles the second version. The created .h file looks like this:
#include "gtk/gtktreestore.h" #include
#if GTK_CHECK_VERSION(2,2,0) struct C2HS_COND_SENTRY_1; #else #endif I don't know how the mechanism is to work but I though that with C2HS_COND_SENTRY_1 defined code segment #1 would be inserted and similar for a C2HS_COND_SENTRY_2 which is kind of missing.
The mechanism works by c2hs running the generated .h through cpp and then checking whether or not `C2HS_COND_SENTRY_1' is defined in the pre-processed header. Anyway, I just checked your example and I think I messed something up in the released version. I'll have a closer look and let you know once it's fixed. Thanks, Manuel