[Haskell-cafe] Using of C constants in Haskell sources; Determining compilation environment (Unix vs Windows)

Bulat Ziganshin bulat.ziganshin at gmail.com
Tue Jul 11 11:28:13 EDT 2006


Hello Haskell,

what is a best way to bring C constant (defined in header file) into
the Haskell source? Haskell project is cabalized and should work with
both Win and Unix while the constants are OS-specific. the best way i
found at this moment is to use the following scheme:

mmap.h:

#if defined(mingw32_HOST_OS) || defined(__MINGW32__) || defined(_MSC_VER)
....
#else
INLINE int const_MAP_FILE( void )
{
  return MAP_FILE;
}
#endif



mmap.hs:

#if defined(mingw32_HOST_OS) || defined(__MINGW32__) || defined(_MSC_VER)
....
#else
foreign import ccall unsafe "mydefs.h const_MAP_FILE"   mAP_FILE   :: CInt
#endif



Second question is how to test whether program compiles under Unix or
Windows environment. Posix/Win32 packages availability would be the
best criterion but it can't be tested :(


-- 
Best regards,
 Bulat                          mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list