Problem using #define in .hsc files

Hi, I'm trying to have hsc2hs interpret this snippet that picks a calling convention to use for FFI imports: #if !defined(CALLCONV) #ifdef WITH_WINSOCK #define CALLCONV stdcall #else #define CALLCONV ccall #endif #endif foreign import CALLCONV unsafe "send" c_send :: CInt -> Ptr a -> CSize -> CInt -> IO CInt Compiling results in: parse error on input `CALLCONV' Inspecting the generated .hs file shows that CALLCONV appear in the source code instead of being replaced with either stdcall or ccall as expected. What's the correct way to use #define in .hsc files? Changing the file extension to .cpphs solves the problem, by using plain CPP instead of hsc2hs I presume. Cheers, Johan

2009/3/29 Johan Tibell
foreign import CALLCONV unsafe "send" c_send :: CInt -> Ptr a -> CSize -> CInt -> IO CInt
Compiling results in:
parse error on input `CALLCONV'
This is what we use in Takusen's Database.ODBC.OdbcFunctions.hsc: #ifdef mingw32_HOST_OS #let CALLCONV = "stdcall" #else #let CALLCONV = "ccall" #endif foreign import #{CALLCONV} unsafe "sql.h SQLAllocHandle" sqlAllocHandle :: SqlHandleType -> Handle -> Ptr Handle -> IO SqlReturn Alistair

In Scurry, I select the CALLCONV on the CPP command line. This might be
better if it's the only place you need an #ifdef.
http://hackage.haskell.org/packages/archive/Scurry/0.0.3/Scurry.cabal
See the OS selection in the executable section:
executable scurry
[..]
if os(mingw32)
c-sources: src/C/help-win.c
extra-libraries: Iphlpapi, ws2_32
cc-options: -D MINGW32
cpp-options: -DCALLCONV=stdcall
if os(linux)
build-depends: unix >= 2.3.0.0
c-sources: src/C/help-linux.c
cc-options: -D LINUX
cpp-options: -DCALLCONV=ccall
/jve
On Mon, Mar 30, 2009 at 4:41 AM, Alistair Bayley
2009/3/29 Johan Tibell
: foreign import CALLCONV unsafe "send" c_send :: CInt -> Ptr a -> CSize -> CInt -> IO CInt
Compiling results in:
parse error on input `CALLCONV'
This is what we use in Takusen's Database.ODBC.OdbcFunctions.hsc:
#ifdef mingw32_HOST_OS #let CALLCONV = "stdcall" #else #let CALLCONV = "ccall" #endif
foreign import #{CALLCONV} unsafe "sql.h SQLAllocHandle" sqlAllocHandle :: SqlHandleType -> Handle -> Ptr Handle -> IO SqlReturn
Alistair _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Alistair Bayley
-
Johan Tibell
-
John Van Enk