title: How do I use variadic arguments with printf in a macro?
body: <p>I have found no way to merge the first printf into the second:</p>
  
  <pre><code>unsigned get_time_now(void) {return 1;}
  #define DEBUG_PRINT 1
  #define debug_tcprintf(fmt, ...) do { \
              if (DEBUG_PRINT) { \
                  unsigned p_time_now = get_time_now(); \
                  printf ("%u ms ", p_time_now); \
                  printf(fmt, __VA_ARGS__); \
              } \
          } while (0)
  </code></pre>
  
  <p>I need to get this done to get an atomic debug_tcprintf. The macro above has been taken from <a href="https://stackoverflow.com/questions/1644868/c-define-macro-for-debug-printing">this Stack Overflow question</a>. </p>
  
  <p>I am doing code in XC that runs on an XMOS multi-logical-core processor. It compiles XC, C and C++, but the code example is from a C code part. It is similar for XC except that it has a timer defined in the language.</p>
  
  <p>If it's not possible to merge the two in one printf, an option may perhaps be to create a string and use sprintf instead? I'd rather not, since such an array might easily overflow.</p>