title: C Error checking macro definition with function call as argument won't compile on MSVC
body: <p>I'm trying to use some code that was targetted at C99 on Windows (MSVC, C11). It's some debugging macro's for OpenCL calls:</p>
  
  <pre><code>#define CL_CHECK(_expr)                                                         \
     do {                                                                         \
       cl_int _err = _expr;                                                       \
       if (_err == CL_SUCCESS)                                                    \
         break;                                                                   \
       fprintf(stderr, "OpenCL Error: '%s' returned %d!\n", #_expr, (int)_err);   \
       abort();                                                                   \
     } while (0)
  
  #define CL_CHECK_ERR(_expr)                                                     \
     ({                                                                           \
       cl_int _err = CL_INVALID_VALUE;                                            \
       typeof(_expr) _ret = _expr;                                                \
       if (_err != CL_SUCCESS) {                                                  \
         fprintf(stderr, "OpenCL Error: '%s' returned %d!\n", #_expr, (int)_err); \
         abort();                                                                 \
       }                                                                          \
       _ret;                                                                      \
     })
  </code></pre>
  
  <p>The first one is used when the return type of _expr is known to be of type cl_int. The second can be of any type, and this is where I run into compilation problems. I replaced typeof(_expr) with "auto", but the compiler keeps complaining with: </p>
  
  <pre><code>  Error 8   IntelliSense: expected an expression    d:\work\Labs\dagSimCL\dagSimCL.cpp  136 23  dagSimCL
    Error 6   error C2143: syntax error : missing ';' before '{'  D:\work\Labs\dagSimCL\dagSimCL.cpp  136 1   dagSimCL
  Error   7   error C2143: syntax error : missing ';' before ')'  D:\work\Labs\dagSimCL\dagSimCL.cpp  136 1   dagSimCL
  Error   5   error C2059: syntax error : '{' D:\work\Labs\dagSimCL\dagSimCL.cpp  136 1   dagSimCL    
  </code></pre>
  
  <p>It doesn't really matter what I throw at the macro, it's always the same. But for reference , this is what I'm doing:</p>
  
  <pre><code>cl_context context = CL_CHECK_ERR(clCreateContext(contextProperties, 1, &amp;devices[device_id], NULL, NULL, &amp;_err));
  </code></pre>
  
  <p>Strangely enough, when I try to wrap the code in a do/while instead of () like in the first macro, it starts complaining about "do". I'm kind of at a loss here. I could just forget about it and skip the error checking, but I want to understand what is going wrong...</p>