C ++宏和预处理器 [英] C++ Macros and the Preprocessor

查看:96
本文介绍了C ++宏和预处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道一本好书或资源,我可以对编写C ++宏有一个深刻的理解。也希望能够涵盖预处理器及其使用的标准宏。



我特别想了解更多关于C ++的这一方面。我意识到有一些简单的例子,但我的目标是要完全理解它们。我确实在基本水平上看不起他们,但我不知道我不知道什么。



如果可能的话绝对喜欢书。有没有人遇到任何关于这个主题领域的问题。



我用Google搜索并询问了一些同事,似乎没有人听说过这种性质的书。也许有一个很好的网络资源,有人可以推荐。



谢谢。

Would anyone know of a good book or resource where I can gain a firm understanding of writing C++ macros. Also hopefully something which will cover the preprocessor and the standard macros it uses.

I specifically want to learn more about this side of C++. I realize there are some simple examples out there but my aim is to gain a complete understanding of them. I do undestand them at a basic level but I don't know what I don't know.

Definitely prefer books if possible. Has anyone come across any covering this topic area well.

I have Googled this and asked some colleagues and it seems nobody has heard of a book of this nature. Maybe there's a good web resource on this somebody can recommend.

Thanks.

推荐答案

最多不太可能你会找到关于这个主题的书,因为宏不是一个特别有用的功能。您可以查看 http://msdn.microsoft.com/en-us/library/y4skk93w。 aspx [ ^ ],它提供了预处理器的详细信息,包括宏。
It is most unlikely you will find a book on the subject, as macros are not a particularly useful feature. You could take a look at http://msdn.microsoft.com/en-us/library/y4skk93w.aspx[^], which provides details of the preprocessor, including macros.


C ++标准怎么样?这不容易阅读,但绝对是参考。



转到 open-std.org:工作草案,编程标准

语言C ++
[ ^ ]或任何较新的版本。预处理器很可能没有改变。



预处理器中有一些棘手的部分:

- 接受的PP号令牌不是必须合法的C / C ++文字

- 重新评估函数宏参数

- 重新评估#和## PP令牌

- PP表达式评估不一定​​与最终程序相同

- 处理一些特殊情况(pragma,行拼接/行编号等)



干杯

Andi
How about the C++ standard? It's not easy to read, but definitively the reference.

Go to open-std.org: Working Draft, Standard for Programming
Language C++
[^] or any newer version. The preprocessor has most likely not changed.

There are a few tricky parts in the preprocessor:
- the accepted PP number tokens are not necessarily legal C/C++ literals
- re-evaluation of function macro arguments
- re-evaluation of # and ## PP tokens
- PP expression evaluation is not necessarily the same as for the final program
- handling some special cases (pragmas, line splicing/line numbering, etc.)

Cheers
Andi


真的,找出你可以做的事情只是谷歌吧。



要记住的重要一点是,宏只是文本的预处理程序。所有文本替换都在任何编译完成之前进行。这是在调用C ++语言之前和变量存在之前。宏是非常有用的,但在制作使用它们的艺术之前总是三思而后行。它们旨在作为文本人工节省设备
Really, to find out the things you can do just google it.

The important thing to remember is that macros are just preproccesors of text. All of the text substitution takes place before any compiling is done. That is before the C++ language is invoked and before variables exist. Macros are very usfull but always think twice before making an art of using them. They are intended as a textual labour saving device


这篇关于C ++宏和预处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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