title: How can I pass a const array or a variable array to a function in C?
body: <p>I have a simple function <code>Bar</code> that uses a set of values from a data set that is passed in in the form of an Array of data structures.  The data can come from two sources: a constant initialized array of default values, or a dynamically updated cache.</p>
  
  <p>The calling function determines which data is used and should be passed to <code>Bar</code>.
  <code>Bar</code> doesn't need to edit any of the data and in fact should never do so.  How should I declare <code>Bar</code>'s data parameter so that I can provide data from either set?</p>
  
  <pre><code>union Foo
  {
  long _long;
  int _int;
  }
  
  static const Foo DEFAULTS[8] = {1,10,100,1000,10000,100000,1000000,10000000};
  static Foo Cache[8] = {0};
  
  void Bar(Foo* dataSet, int len);//example function prototype
  </code></pre>
  
  <p>Note, this is C, NOT C++ if that makes a difference;</p>
  
  <p><em>Edit</em><br>
  Oh, one more thing. When I use the example prototype I get a type qualifier mismatch warning, (because I'm passing a mutable reference to a const array?).  What do I have to change for that?</p>