tags:

views:

98

answers:

1

I have a C header file (it's a part of some SDK) and there is a typedef which depends on system architecture (whether it is 32 or 64-bit), how do I transfer it to my D module? Thanks.

Edit: OK, that was too simple and I've already find a solution... If someone interested, it is:

version(X86) {
  typedef int your_type;
}
version(X86_64) {
  typedef long your_type;
}
+9  A: 
version(X86)
{
    // 32-bit
}
else
version(X86_64)
{
    // 64-bit
}
else
{
    // none of the above
}

Source: http://digitalmars.com/d/2.0/version.html

CyberShadow
Thanks. Btw is there any analogue of C's #error in D so I can show a compile time error in "none of above" case?
Zeex
You could do `static assert(0)` inside the `else` block.
You
What You said. :P
CyberShadow
static assert(false, "message"); is probably the best choice. You can also print messages without killing compilation: pragma(msg, "Message");
he_the_great