C++宏解释
有人可以解释一下下面的代码吗?
#if 1
// loop type
#define FOR_IS_FASTER 1
#define WHILE_IS_FASTER 0
// indexing type
#define PREINCREMENT_IS_FASTER 1
#define POSTINCREMENT_IS_FASTER 0
#else
// loop type
#define FOR_IS_FASTER 1
#define WHILE_IS_FASTER 0
// indexing type
#define PREINCREMENT_IS_FASTER 0
#define POSTINCREMENT_IS_FASTER 1
#endif
#if PREINCREMENT_IS_FASTER
#define ZXP(z) (*++(z))
#define ZX(z) (*(z))
#define PZ(z) (++(z))
#define ZP(z) (z)
#define ZOFF (1)
#elif POSTINCREMENT_IS_FASTER
#define ZXP(z) (*(z)++)
#define ZX(z) (*(z))
#define PZ(z) (z)
#define ZP(z) ((z)++)
#define ZOFF (0)
#endif
我可以理解这些功能在做什么,但是例如 如果我们稍后调用它,预处理器如何选择将执行哪个 ZXP? 1和0代表什么?
Can somebody explain the following code please?
#if 1
// loop type
#define FOR_IS_FASTER 1
#define WHILE_IS_FASTER 0
// indexing type
#define PREINCREMENT_IS_FASTER 1
#define POSTINCREMENT_IS_FASTER 0
#else
// loop type
#define FOR_IS_FASTER 1
#define WHILE_IS_FASTER 0
// indexing type
#define PREINCREMENT_IS_FASTER 0
#define POSTINCREMENT_IS_FASTER 1
#endif
#if PREINCREMENT_IS_FASTER
#define ZXP(z) (*++(z))
#define ZX(z) (*(z))
#define PZ(z) (++(z))
#define ZP(z) (z)
#define ZOFF (1)
#elif POSTINCREMENT_IS_FASTER
#define ZXP(z) (*(z)++)
#define ZX(z) (*(z))
#define PZ(z) (z)
#define ZP(z) ((z)++)
#define ZOFF (0)
#endif
I can understand what the functions are doing but for example
how does the pre-processor choose which ZXP will be execute if we call it later?
What do the 1 and 0 stand for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
#if 1
触发第一组#define
,将 PREINCRMENT_IS_FASTER 设置为 1。因此,#if PREINCRMENT_IS_FASTER
触发第一个#define ZXP...
。在这种情况下,1 和 0 并没有什么特殊之处。如果
#if
预处理器指令的参数非零,则该指令成功。您可以通过将文件顶部的
#if 1
更改为#if 0
来切换到备用形式。 (谢谢@rabidmachine 的提示。)The
#if 1
triggers the first group of#define
s, which set PREINCREMENT_IS_FASTER to 1. Because of this,#if PREINCREMENT_IS_FASTER
triggers the first#define ZXP...
.There is nothing exceptional about 1 and 0 in this context. The
#if
preprocessor directive succeeds if its argument is non-zero.You can switch to the alternate form by changing the
#if 1
at the top of the file with#if 0
. (Thank you @rabidmachine for the tip.)我可能倾向于同意 UncleBens 的观点,并建议这样做是为了让你不理解它,因为所有这些都是完全无用的。
I'm probably inclined to agree with UncleBens and suggest that it's done so that you don't understand it, because the whole lot is totally useless.