宏扩展 [英] Macro Expansion
问题描述
基本问题
#define A 5
#define B 10
#define C (A*B)
int var;
var = C;
所以这里宏将如何扩大,是不是
so here how macros will be expanded, Is it
var = (5*10)
或
var = (50)
我的怀疑是对宏扩展。如果宏有一定的计算 - 在所有常数(*,/,+),然后将马可只是在网上膨胀或将评估结果,并张贴
My doubt is on the macro expansion. If macros has some calculations (*,-,/,+) on all constant,then will marco is just a in line expansion or it will evaluate the result and post it
推荐答案
宏扩展是永远只是一个文本转换输入源$ C $ C的。你应该能够看到code中的pre处理器(即不宏扩展汇编的一部分)完成后,本文是编译器正确,然后对工作
Macro expansion is always just a textual transform of the input source code. You should be able to see the code after the pre-processor (the part of the compilation that does the macro expansion) is done; this text is what the compiler proper then works on.
但是,许多编译器做在编译过程中常量折叠的优化,这将优化 5 * 10
到 50
等等它并不需要在运行时计算。
But many compilers do "constant folding" optimization during compilation, that will optimize 5 * 10
to 50
so that it doesn't need to be calculated at runtime.
这篇关于宏扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!