version() abuse! Note of library writers.

Sean Kelly sean at invisibleduck.org
Wed Nov 18 07:37:01 PST 2009


Travis Boucher Wrote:

> 
> The problem I run into is the assumption that linux == unix/posix.  This 
> assumption is not correct.
> 
> The use of version(linux) should be limited to code that:
> 
> 1. Declares externals from sys/*.h
> 2. Accesses /proc or /sys (or other Linux specific pseudo filesystems)
> 3. Things that interface directly with the dynamic linker (eg. linking 
> against libdl)
> 4. Other things that are linux specific....
> 
> Anything that accesses standard libc functions, standard unix semantics 
> (eg. signals, shm, etc) should use version(Posix) or version(unix).

It may help to think about weird configurations like targeting Cygwin on Windows (where Windows, Win32, and Posix may theoretically be defined) or WINE on Linux (where linux and Win32 may be defined).  I haven't really considered the latter situation, but the former is handled correctly in D2.  As you've said, the best idea is to version for the API you're targeting rather than the OS you're on.  For the most part, a version also corresponds to a package in core.sys in D2.  core.sys.posix contains pretty much everything *nix folks are used to, with core.sys.osx and core.sys.linux containing kernel APIs, etc.



More information about the Digitalmars-d mailing list