title: Creating helper function with static character array
body: <p>I am using PostgreSql C library <code>libpq</code>, and I can fetch values from the <code>PGresult</code> pointer with <code>PQgetvalue</code> function.</p>
  
  <p>Now, I have a table with 10-20 columns, and I want to print them out with a simple <code>printf</code> call:</p>
  
  <pre><code>printf("%s,%s,%s..(so on...)...%s", resA, resB, resC,..., resN);
  </code></pre>
  
  <p>where <code>resA</code> to <code>resB</code> are strings loaded using <code>PGgetvalue</code> function. Now, this approach requires 10-20 pointers declared (if I want to print it out with a single printf), and I was going to use something simple as:</p>
  
  <pre><code>char* getFieldVal(PGresult* res, int row, char* fieldName)
  {
      static char tmp[1000];
      memset(tmp, 0, sizeof(tmp));
  
      // Load data here...
  
      return tmp;
  }
  </code></pre>
  
  <p>and then to call <code>printf</code> like:</p>
  
  <pre><code>printf("%s,%s,%s..(so on...)...%s", 
         getField(r, 0, "A"), getField(r, 0, "B"), ... , getField(r, 0, "N"));
  </code></pre>
  
  <p>However, output of the <code>printf</code> function is indicating that all <code>getField</code> calls are returning whatever first was requested from the database (in this case, value of the <code>A</code> field), even though I've deleted the previous string (just to be sure) with <code>memset</code> call.</p>
  
  <p>Where am I wrong? Is something in my code, or is gcc assuming that all my getField calls returns pointer to the same memory, so it is not actually calling it mulitple times. </p>
  
  <p>Or, is <code>printf</code> function first evaluating all parameters (in reverse order), and then actually calling the function? If this is the case (and I bet it is), is there any simpler pattern to achieve what I am trying?</p>