c语言宏函数怎么传递宏参数_C语言中的宏参数评估

2023-05-16

c语言宏函数怎么传递宏参数

We can define a function like Macro, in which we can pass the arguments. When a Macro is called, the Macro body expands or we can say Macro Call replaces with Macro Body.

我们可以定义一个函数,例如Macro,可以在其中传递参数。 调用宏时,宏主体会展开,或者可以说宏调用被宏主体替换

Now, the important thing is that: How Macro arguments evaluate? - "Macro arguments do not evaluate before Macro expansion, they evaluate after the expansion."

现在,重要的是: 宏参数如何计算? - “宏参数在宏扩展之前不评估,而在扩展之后评估。”

Consider the example:

考虑示例:

#include <stdio.h>

#define CALC(X,Y) (X*Y)

int main()
{ 
	printf("%d\n",CALC(1+2, 3+4));
	return 0;
}

Output

输出量

11

Explanation:

说明:

If you are thinking that 1+2 and 3+4 will be evaluated before the expansion and it will be expanded as 3*7 then, you are wrong.

如果您认为在扩展之前将对1 + 2和3 + 4进行求值,并且将其扩展为3 * 7,那么您错了。

The arguments evaluate after the call, thus Macro CALC(1+2,3+4) will be expanded as = (1+2*3+4) = (1+6+4) =(11).

参数在调用后求值,因此Macro CALC(1 + 2,3 + 4)将扩展为=(1 + 2 * 3 + 4)=(1 + 6 + 4)=(11)

Finally, the output will be 11.

最后, 输出将为11

翻译自: https://www.includehelp.com/c-programs/macro-arguments-evaluation-in-c.aspx

c语言宏函数怎么传递宏参数

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

c语言宏函数怎么传递宏参数_C语言中的宏参数评估 的相关文章

随机推荐