#define 是否应该在宏周围添加空格?

编程入门 行业动态 更新时间:2024-10-24 23:26:31
本文介绍了#define 是否应该在宏周围添加空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 www0.us.ioccc 查看该计划/1988/westley.c,在 另一个 SO 答案 - 它应该打印 pi 的值,大约 3.142,但是当我编译并运行它时,我得到 0.250.看起来当 GCC 预处理器(测试的 4.1.2 和 3.4.6)在代码上运行时,它会转换

I was looking at the program at www0.us.ioccc/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?)

编辑:另外,任何有关如何防止这些空间出现的信息都将不胜感激.

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

推荐答案

预处理器对标记进行操作,而不是严格的文本.所以从技术上讲,它不会在两者之间放置一个空格",但除非你明确告诉它将两个标记与 ## 运算符一起粘贴,否则它不会这样做.在这种情况下,跨宏行的两个 - 被计为两个不同的标记 - 都表示一元减号,而不是减量.

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.

另见:en.wikipedia/wiki/C_preprocessor#Token_concatenation

更多推荐

#define 是否应该在宏周围添加空格?

本文发布于:2023-11-14 02:57:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586027.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空格   define

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!