title: Detecting null parameter in preprocessor macro
body: <p>I have the following macro function in vanilla <strong>C</strong>:</p>
  
  <pre><code>#define GLOG(format_string, ...) { \
    const char *file = strrchr(__FILE__, '/'); \
    char format[256] = "%s:%s!%d\t"; \
    strncat(format, format_string, 248); \
    strcat(format, "\n"); \
    printf(format, __FUNCTION__, file ? file : __FILE__, __LINE__, ##__VA_ARGS__); \
  }
  </code></pre>
  
  <p>which lets me print a debug message containing the current function, file and line number, e.g.</p>
  
  <pre><code>GLOG("count=%d", count);
  </code></pre>
  
  <p>might print</p>
  
  <pre><code>do_count:counter.c!123  count=456
  </code></pre>
  
  <ol>
  <li><p>How can I modify the function to print all local variables if caller omits format_string? e.g.</p>
  
  <pre><code>GLOG();
  </code></pre>
  
  <p>might print</p>
  
  <pre><code>do_count:counter.c!123  count=456, message="Hello world", array=[7, 8] structure={ptr=0xACE0FBA5E, coord={x=9, y=0}}
  </code></pre></li>
  <li><p>If that's not possible, how can I modify it to print just the current function, file and line number? e.g.</p>
  
  <pre><code>do_count:counter.c!123
  </code></pre>
  
  <p>As is, this returns an error:</p>
  
  <blockquote>
    <p>error: expected expression before ‘,’ token</p>
  </blockquote>
  
  <p>as the <code>strncat</code> line is simply</p>
  
  <pre><code>strncat(format, , 248);
  </code></pre></li>
  </ol>