Recommended coding convention for combining unix and windows code ?
chmike via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 7 08:33:57 PDT 2016
Hello
I'm writing some code that I want to be portable across Posix and
Windows.
What is the recommended code convention for such type of code ?
80% of the class implementation is the same for both OS.
Should I write the following and copy past the 80%
version( Windows ) {
import core.sys.windows;
class MyInfo {...}
} else version( Posix ) {
import core.sys.posix;
class MyInfo {...}
} else {
static assert(false, "Unsupported platform");
}
or should I do it the C way with multiple embedded static if... ?
version( Windows ) {
import core.sys.windows;
} else { //Posix
import core.sys.posix;
}
class MyInfo {
...
static if(windows) {
enum Value {...}
} static else { //Posix
enum Value {...}
}
...
}
More information about the Digitalmars-d-learn
mailing list