[C2hs] preprocessor questoin
Axel Simon
A.Simon@ukc.ac.uk
Sat, 12 Apr 2003 18:48:58 +0100
Hi Manuel,
I am trying to use the conditional compilation feature of the latest release of c2hs. My
code looks something like this:
#include <gtk/gtkversion.h>
#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...).
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 <gtk/gtkversion.h>
#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. So I tried to split the two cases into two single if statements:
#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
#endif
#if !GTK_CHECK_VERSION(2,2,0)
treeStoreRemove :: (TreeStoreClass ts) => ts -> TreeIter -> IO ()
treeStoreRemove ts ti = {#call tree_store_remove#} (toTreeStore ts) ti
#endif
This yields:
#include "gtk/gtktreestore.h"
#include <gtk/gtkversion.h>
#if GTK_CHECK_VERSION(2,2,0)
struct C2HS_COND_SENTRY_1;
#endif
#if !GTK_CHECK_VERSION(2,2,0)
struct C2HS_COND_SENTRY_2;
#endif
...and not not a single version of treeStoreRemove winds up in the resulting file.
Am I doing something wrong or is c2hs wrong?
Thanks,
Axel.