title: How to reset static variables within a function
body: <p>Is there a way to reset variables declared as static within a function? The goal is to make sure that the function is not called with lingering values from an unrelated call.  For example, I have a function opearting on columns of a matrix. </p>
  
  <pre><code>int foo(matrix *A, int colnum, int rownum){
  static int whichColumn;
  static int *v; //vector of length A-&gt;nrows 
     if (column != whichColumn){
      memset(v,0,size);
      whichColumn = which;
     } 
     //do other things
  }
  </code></pre>
  
  <p>The function is called n times, once for each column.  Is this a proper way of "re-setting" the static variable? Are there other general fool-proof ways of resetting static variables? For example, I want to make sure that if the call is made with a new matrix with possibly different dimensions then the vector v is resized and zeroed etc. It seems the easiest way may be to call the function with a NULL pointer:</p>
  
  <pre><code>int foo(matrix *A, int colnum, int rownum){
  static int whichColumn;
  static int *v; //vector of length A-&gt;nrows 
     if (A == NULL){
      FREE(v);
      whichColumn = 0;
     } 
     //do other things
  }
  </code></pre>