在C/C++中,我们有预处理程序指令(参见问题的标题).D语言中它们的类比是什么?如何在编译时检测操作系统类型(Windows,Linux,Mac OS X,FreeBSD,...)和处理器类型(例如:32位或64位)?
更新:最佳答案已经在dlang.org上:http://dlang.org/pretod.html .
D没有预处理器.相反,它提供了强大的编译时评估和内省功能.
以下是典型的C/C++到D翻译的简单列表,其中包含相关文档的链接:
C/C++:#ifdef,#ifndef,#else,#elif
D:version[ 链接 ]
C/C++:#if <condition>
D:static if[ 链接 ]
C/C++:#define
D:D翻译取决于具体情况.
简单的C/C++定义就像#define FOO被翻译成D的" 版本 ".例:version = FOO
代码#define BAR 40转换为以下D代码:enum BAR 40或者在极少数情况下,您可能需要使用alias.
复杂定义喜欢#define GT_CONSTRUCT(depth,scheme,size) \
    ((depth) | (scheme) | ((size) << GT_SIZE_SHIFT))翻译成D的模板:
// Template that constructs a graphtype
template GT_CONSTRUCT(uint depth, uint scheme, uint size) {
  // notice the name of the const is the same as that of the template
  const uint GT_CONSTRUCT = (depth | scheme | (size << GT_SIZE_SHIFT));
}
Run Code Online (Sandbox Code Playgroud)
(来自D维基的例子)
C/C++:#undef
D:我知道没有足够的翻译
#if condition被替换为static if(condition)(编译时评估更多)
#ifdef ident 被替换为 version(ident)
#define ident 被替换为 version = ident
#define ident replacement 被替换为 alias ident replacement 
有关http://dlang.org/version.html的更多信息以及预定义版本定义列表