3

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
    See possible duplicate: [Are compund statements (blocks) surrounded by parens expressions in ANSI C?](http://stackoverflow.com/q/1238016/1708801) ... as my answer to the that question says: *last thing in the compound statement should be an expression followed by a semicolon; the value of this subexpression serves as the value of the entire construct.* – Shafik Yaghmour Jun 01 '15 at 14:55

1 Answers1

9

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.

Quentin
  • 62,093
  • 7
  • 131
  • 191