是应该的#define周围添加宏空间? [英] Is #define supposed to add spaces around macros?

查看:99
本文介绍了是应该的#define周围添加宏空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 http://www0.us.ioccc.org看节目/1988/westley.c ,在另一SO回答 - 它应该打印PI,约3.142的价值,但是当我编译并运行它,我得到 0.250 。它看起来当GCC preprocessor(包括4.1.2和3.4.6测试)在code运行状,将其转换

I was looking at the program at http://www0.us.ioccc.org/1988/westley.c, mentioned in another SO answer - it's supposed to print the value of pi, about 3.142, but when I compile it and run it I get 0.250. It looks like when the GCC preprocessor (both 4.1.2 and 3.4.6 tested) runs on the code, it converts

#define _ -F<00||--F-OO--;
_-_-_

-F<00||--F-OO--;- -F<00||--F-OO--;- -F<00||--F-OO--;

但我认为,该计划的工作,它应该是

but I think, for the program to work, it should be

-F<00||--F-OO--;--F<00||--F-OO--;--F<00||--F-OO--;

即。 GCC被插入的宏扩张之前额外的空间。是的方式的#define 应该工作? (有自1988年以来改变了吗?)

i.e. GCC is inserting an extra space before the "macro" expansion. Is that the way #define is supposed to work? (Has that changed since 1988?)

修改的。此外,有关如何prevent任何信息的空间无法显示了将AP preciated

EDIT: Also, any information about how to prevent those spaces from showing up would be appreciated.

推荐答案

在preprocessor令牌上操作,没有严格的文本。因此从技术上讲并不把空间之间,但除非你明确告诉它两个标记与 ## 运营商贴在一起,它不会做。在这种情况下,两个 - 的整个宏观行被视为两个不同的标记 - 既意味着一元减,不减少

The preprocessor operates on tokens, not strictly text. So technically it doesn't "put a space" in between, but unless you explicitly tell it to paste two tokens together with the ## operator, it won't do it. In this case the two -'s across macro lines are counted as two different tokens - both meaning unary minus, not decrement.

另见: http://en.wikipedia.org/wiki/C_ $ p $#pprocessor ​​ Token_concatenation

see also: http://en.wikipedia.org/wiki/C_preprocessor#Token_concatenation

这篇关于是应该的#define周围添加宏空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆