title: C - How to use multiple functions in macros?
body: <p>Currently building a simple webserver in c.
  To improve the code I want to use makros and spefically I want to use multiple functions inside a single makro to print an error message and quit the program afterwards.</p>
  <p>The following code works without pedantic error messages but I would like to know why ISO-C forbids this or where my error is.</p>
  <p>Compiler info:</p>
  <pre class="lang-sh prettyprint-override"><code>gcc -O0 -g3 -pedantic -pedantic-errors -Wall -Wextra -Werror error_makro.c
  </code></pre>
  <p>Code:</p>
  <pre class="lang-c prettyprint-override"><code>#define CHECK(x,m) ((x) &lt; 0) ? ({perror(m); exit(1);}) : (NULL)
  
  void createWebSocket(simpleWebServer *self){
  
      struct addrinfo hints, *res;
      memset(&amp;hints, 0, sizeof(hints));
  
      hints.ai_family = AF_UNSPEC;
      hints.ai_flags = AI_PASSIVE;
      hints.ai_socktype = SOCK_STREAM;
  
  
      CHECK(getaddrinfo(NULL, self-&gt;port, &amp;hints, &amp;res), &quot;getaddrinfo&quot;);
  
      if((self-&gt;serverSocket = socket(res-&gt;ai_family, res-&gt;ai_socktype, res-&gt;ai_protocol)) &lt; 0){
          perror(&quot;socket&quot;);
          exit(2);
      }
      if(bind(self-&gt;serverSocket, res-&gt;ai_addr, res-&gt;ai_addrlen) &lt; 0){
          perror(&quot;bind&quot;);
          exit(3);
      }
      if(listen(self-&gt;serverSocket, BACKLOG) == -1){
          perror(&quot;listen&quot;);
          exit(4);
      }
      freeaddrinfo(res);  
  }
  </code></pre>
  <p>Error message:</p>
  <pre class="lang-sh prettyprint-override"><code>error_makro.c: In function ‘main’:
  error_makro.c:6:32: error: ISO C forbids braced-groups within expressions [-Wpedantic]
      6 | #define CHECK(x,m) ((x) &lt; 0) ? ({perror(m); exit(1);}) : (NULL)
        |                                ^
  error_makro.c:11:5: note: in expansion of macro ‘CHECK’
     11 |     CHECK(-1, &quot;test&quot;);
        |     ^~~~~
  error_makro.c:6:56: error: ISO C forbids conditional expr with only one void side [-Wpedantic]
      6 | #define CHECK(x,m) ((x) &lt; 0) ? ({perror(m); exit(1);}) : (NULL)
        |                                                        ^
  error_makro.c:11:5: note: in expansion of macro ‘CHECK’
     11 |     CHECK(-1, &quot;test&quot;);
        |     ^~~~~
  </code></pre>