[Haskell-cafe] hsc2hs: expanding macros in the .hsc file

Olivier Boudry olivier.boudry at gmail.com
Tue May 13 13:42:48 EDT 2008

Hi all,

Is it possible to expand macros defined in includes into the .hsc file? I'm
trying to call functions from a library written in C. The library can be
used with or without Unicode chars, depending on #define instructions.

The library has macros for all the standard functions used to work on
strings (malloc, strlen, strcpy, strtok, ...). So that in code using the
library one can always call the macro and don't care about the char type
(strlenU instead of wcslen or strlen). Macro expansion will define which
function will be used depending on the SAPwithUNICODE #define. I put a very
simplified example below. The original file contains much more conditions
(OS, Unicode or not, little or big endian, ...).

#define strlenU                     SAP_UNAME(strlen)

#ifdef SAPwithUNICODE
  #define SAP_UNAME(name)            name##U16
  #define SAP_UNAME(name)            name

#if defined(WCHAR_is_2B)
  #define strlenU16                       wcslen

I would like to be able to expand strlenU in my .hsc file and get the
correct function.

foreign import ccall "static sapuc.h strlenU"
  f_strlenU :: Ptr (#type SAP_UC) -> IO (#type size_t)

I would like to be able to expand the strlenU macro to the real function
name (wcslen or strlen). Is there a way to do this?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080513/654b6137/attachment.htm

More information about the Haskell-Cafe mailing list