title: Inconveniences of pointers to static variables
body: <p>I often use convenience functions that return pointers to static buffers like this:</p>
  
  <pre><code>char* p(int x) {
      static char res[512];
  
      snprintf(res, sizeof(res)-1, "number is %d", x));
  
      return res;
  }
  </code></pre>
  
  <p>and use them all over the place as arguments to other functions:</p>
  
  <pre><code>...
  some_func( somearg, p(6) );
  ....
  </code></pre>
  
  <p>However, this "convenience" has an annoying drawback besides not being thread-safe (and probably many more reasons):</p>
  
  <pre><code>some_func( somearg, p(6), p(7) );
  </code></pre>
  
  <p>The above obviously doesn't do what I want since the last two arguments will point to the same memory space. I would like to be able get the above to work properly without to many hassles.</p>
  
  <p>So my question is:</p>
  
  <p><strong>Is there some magic way I have missed to accomplish what I want without doing cumbersome allocation &amp; freeing?</strong></p>
  
  <p>***** UPDATE 2010-04-20 *****</p>
  
  <p>Shameless plug: look at my own answer <a href="https://stackoverflow.com/questions/2231317/inconveniences-of-pointers-to-static-variables/2677237#2677237">here</a></p>
  
  <p>I guess it will work but it's also bordering to overkill. Opinions?</p>