简体   繁体   English

这个宏是什么意思#define div_ac_power(y,x)* y / x

[英]What does this macro mean #define div_ac_power(y,x) *y/x

#define div_ac_power(y,x)           *y/x

Shall y be an address? 请问您是住址吗? As far as I understand it returns the result of division between a pointer (y) and whatever object is x. 据我了解,它返回指针(y)和任何对象x之间的除法结果。

As far as I understand it returns the result of division between a pointer (y) and whatever object is x. 据我了解,它返回指针(y)和任何对象x之间的除法结果。

That is probably the intention. 这可能是意图。

The macro needs more parenthesis to secure it from misuse. 宏需要更多的括号以防止滥用。

Consider the following cases: 考虑以下情况:

Case 1. Compound parameter: 情况1.复合参数:

result= div_ac_power(y,a+b);

which is expanded to: 扩展为:

result = *y/a+b; // This equals (*y/a)+b because of operator precedence.

Case 2. Fooling around: 情况2。

result= a div_ac_power(y,b); // Note the lack of operator between a and macro

which is expanded to: 扩展为:

result= a*y/b; // This may well be a valid expression depending on the types of a, b, y.

To fix it, you could add parenthesis: 要解决此问题,您可以添加括号:

#define div_ac_power(y,x)           (*(y)/(x))
  1. Dereference the value pointed-to by y pointer 解引用y指针指向的值
  2. Divide this value by x value 将该值除以x

Same as: 如同:

int *y, x; // init them
int z = *y;
int res = z / x;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM