C ++宏中的语句 [英] Statement in C++ macro
问题描述
阅读铬代码,发现对处理符合POSIX的系统上的系统调用的EINTR errno有用的宏. 这是代码(base/posix/eintr_wrapper.h):
Reading chromium code, found helpful macro for handling EINTR errno of system calls on POSIX compliant systems. Here are the code(base/posix/eintr_wrapper.h):
#define HANDLE_EINTR(x) ({ \
decltype(x) eintr_wrapper_result; \
do { \
eintr_wrapper_result = (x); \
} while (eintr_wrapper_result == -1 && errno == EINTR); \
eintr_wrapper_result; \
})
问题是宏eintr_wrapper_result;
中last语句的作用是什么?
如果我们使用逗号而不是分号-将会很明显-返回上一个运算的结果(逗号运算符).但是在这种情况下,目的是什么?
The question is what is the role of last statement in macro eintr_wrapper_result;
?
If we use commas instead of semicolons - it will be clear - to return the result of last operation(comma operator). But what is purpose in this case?
推荐答案
此宏使用 Statement-Expressions GCC扩展名.一旦执行完毕,内部块中的最后一个表达式将作为整个值,就像逗号运算符一样.
This macro uses the Statement-Expressions GCC extension. The last expression in the inner block serves as the value for the whole, once it has been executed, much like the comma operator.
这篇关于C ++宏中的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!