different code in different platforms

Sorry. In the previous email I forgot the subject. Hi Im having a small problem with the portability of my Haskell code. My code uses wxHaskell and the library for which this one is the Haskell interface (that is called wxWidgets) doesnt work in the same away in Windows and Linux. Now I now which code run in Linux and in Windows but I dont want to have to manually change the file in each platform. I tried a solution using the C pre-processor but I getting in trouble. I use code like: #ifdef __WIN32__ (Windows code) #else (Linux code) #endif I also add the --cpp to the ghc and it works for me in Linux but give me linking errors in Windows. Does someone have any hints on how to have different code in Windows and Linux? I would be thankful in some help. Best regards Miguel Vilaça

Hi, Does it really have to change statically?
I use code like: #ifdef __WIN32__ (Windows code) #else (Linux code) #endif
In Yhc, we use a runtime test to check between Windows and Linux. It has various advantages - we only have one code base, everything is type checked when we compile, and we've never run into any problems once despite developing on two different platforms. http://www-users.cs.york.ac.uk/~malcolm/cgi-bin/darcsweb.cgi?r=yhc-devel;a=h... Thanks Neil

Neil Mitchell wrote:
Does it really have to change statically?
I use code like: #ifdef __WIN32__ (Windows code) #else (Linux code) #endif
In Yhc, we use a runtime test to check between Windows and Linux. It has various advantages - we only have one code base, everything is type checked when we compile, and we've never run into any problems once despite developing on two different platforms.
http://www-users.cs.york.ac.uk/~malcolm/cgi-bin/darcsweb.cgi?r=yhc-devel;a=h...
There's a lot to be said for using runtime tests instead of conditional compilation, I agree. However, it can't be used exclusively: you can't choose between two foreign calls this way, for example, because one of the calls won't link. Cheers, Simon

On Wed, Mar 15, 2006 at 04:13:19PM +0000, Simon Marlow wrote:
There's a lot to be said for using runtime tests instead of conditional compilation, I agree. However, it can't be used exclusively: you can't choose between two foreign calls this way, for example, because one of the calls won't link.
A scheme I was considering for jhc was to (optionally) replace any foreign calls that don't link with 'error', a solution for ghc might be to include stub functions with the 'weak' attribute set in the object file for any potentially non-existing functions. then the system versions will override them if they exist, otherwise the stub functions will be called. perhaps there is room for a FFI extension there? allowing 'weak' to be specified on FFI imports that means 'don't complain if the system doesn't provide this function' John -- John Meacham - ⑆repetae.net⑆john⑈

Neil Mitchell wrote:
#ifdef __WIN32__ (Windows code) #else (Linux code) #endif
In Yhc, we use a runtime test to check between Windows and Linux.
I think the cleanest solution is to factor the OS-specific code into separate modules with OS-independent interfaces and names, and pull in the appropriate implementations at compile time by changing the module search path. That way you avoid the syntactic and semantic ugliness of cpp as well as most of the practical problems of a runtime test. You can also use any two or all three of these techniques together. -- Ben
participants (5)
-
Ben Rudiak-Gould
-
John Meacham
-
José Miguel Vilaça
-
Neil Mitchell
-
Simon Marlow