
Am Sonntag, 23. Oktober 2005 03:47 schrieb Donald Bruce Stewart:
How do we deal with portability issues in nhc? The code I submitted will run find on the BSDs and Linux, but for Solaris, Irix, HPUS, and Darwin when need slight variations (which ghc currently has) (and we're stuck with malloc on Windows).
Does nhc have some equivalent of the #if defined(solaris2_HOST_OS) || defined(irix_HOST_OS) macros?
[ putting on my autotools hat again... ] Unless you *really* care about the OS, never use #ifdefs like the ones above, they are a source of constant maintenance trouble. Feature-based #ifdefs are the way to go, and this is e.g. the central point of the highly successful autotools toolchain. In our case at hand we should check for the availability of mmap (and perhaps its flags) and use the code you gave if it is available, falling back to malloc if it is not. Even if we are lazy and don't want to do a real feature detection at configuration time, using feature-based #ifdefs in the code is still the right way to go, because then the build system can #define the feature-based #ifdefs in a single place depending on the OS, which is much easier to maintain. Cheers, S.