Statement in C++ macro

别来无恙 提交于 2019-12-01 22:37:46

问题


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; \
})

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?


回答1:


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.



来源:https://stackoverflow.com/questions/30576644/statement-in-c-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!