English 中文(简体)
加工商如何处理宏观问题?
原标题:How are macros handled by preprocessor?

I am reading Efficient c++ (older version) and have some doubts. Here, for example, it says:

当你做这样的事情时

#define ASPECT_RATIO 1.653

the symbolic name ASPECT_RATIO may never be seen by the compilers; it may be removed by the preprocessors before the source code ever gets compiled. As a results the ASPECT_RATIO may never get entered to SYMBOLIC_TABLE. It an be confusing if you get an error during compilation involving the constant, because the error message may refer to 1.653 and not ASPECT_RATIO

我不理解这一段。 如何去除加工前者,就如此。 在现实世界中,这些原因和可行性是什么。

增 编

最佳回答

I don t understand this paragraph under inverted quotes.How can anything be removed the preprocessor, just like that. what could be the reasons and how feasible are they in real world.

基本上,它所描述的是C和C++的加工前工作方式。 原因是用实际价值取代宏观/企业(使用<代码>#define指令),而不是重复同样的价值。 在C++中,它被视为一种使用C类宏观的坏风格,但是它们重新支持C兼容。

原始处理器如名称所示,在实际汇编之前运行,基本上根据加工前指令(从<代码>#开始)修改源代码。 这也包括用其价值取代宏观,按照<代码>#include 指令等指示列入头号档案。

这样做是为了避免编码重复、磁性编号、共享接口(档案)和许多其他有用的东西。

问题回答

它只是全球搜索,在档案中将“ASPECT_RATIO”改为“1.653”,然后提交汇编者。

因此,宏观因素非常危险。 如果您有<代码>#define max 123和一份可变的<编码>int max = 100,汇编者将获得int 123 = 100<<>>>,并将获得一个混淆的错误信息。

预处理器将取代在编码中以实际编号为<代码>1.653<>代码/代码>显示的星号的所有实例。 ......因此,汇编者将永远不会看到打字的<条码>ASPECT_RATIO。 在编纂该守则时,它只见前处理人所替代的字面编号<>1.653。

基本上,你会遇到的“问题”是,伙伴关系项目。 RATIO将不会被汇编者视为一个象征,因此,在夸张中,你可以质疑ASPECT的价值。 RATIO是个变量。 它的价值不在于像/code>static const int”这样的记忆地址(我说“可以”),因为优化的汇编者可能决定像处理前者一样行事,并优化使用明确的记忆地址以储存固定价值的必要性,而仅仅是在守则中出现的面值。 在较大的职能宏观中,它获得的指令地址也像C/C++的实际功能一样,因此,你可以在职能宏观中设置突破点。 但从更广的意义上来说,我不敢肯定,除非你打算将宏观作为代谢物,和/或在你的宏观中确定分点。 否则,宏观工作就是做的。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签