title: how do I assign a function to an element of an array of function pointers
body: <p>In Xcode 7.2.1, I declare 3 C functions  </p>
  
  <pre><code>double function1(double);
  double function2(double);
  double function3(double);
  </code></pre>
  
  <p>Now I declare a pointer to a function and define it. </p>
  
  <pre><code>double (*aFunctionPointer)(double)=function1;
  </code></pre>
  
  <p>No errors, as expected.</p>
  
  <p>Now I declare an array of function pointers and fill it with my 3 functions. </p>
  
  <pre><code>double (*anArrayOfFunctionPointers[3])(double)={function1, function2, function3};
  </code></pre>
  
  <p>Again, no errors.</p>
  
  <p>Now I define an array of function pointers, but do not fill it.</p>
  
  <pre><code>double (*anotherArrayOfFunctionPointers[3])(double);
  </code></pre>
  
  <p>Again, no errors.</p>
  
  <p>Now I try to assign a function to one of the array elements. </p>
  
  <pre><code>anotherArrayOfFunctionPointers[1]=function2;
  </code></pre>
  
  <p>This time, warnings and errors:</p>
  
  <ul>
  <li>Warning: Type specifier missing, defaults to int</li>
  <li>Error: Redefinition of 'anotherArrayOfFunctionPointers' with a different type:'int [0]' vs 'double (*[3]) (double)'</li>
  </ul>
  
  <p>I am stumped.</p>
  
  <p>The background is that I am trying to write a program to convert between various units of measure. I thought I would use a two-dimensional array containing function pointers, in order to avoid a number of very lengthy switch statements.</p>
  
  <p>To make a conversion, I would call a function as follows:</p>
  
  <pre><code>result=convert(someValueToConvert,yards,meters);
  </code></pre>
  
  <p>and the convert function would invoke the correct function from the array like so: </p>
  
  <pre><code>return conversionFunctionArray[yards, meters](someValue);
  </code></pre>
  
  <p>The array would be initialized like so:</p>
  
  <pre><code>conversionFunction[yards][meters]=yardsToMeters(somevalue);
  conversionFunction[meters][yards]=metersToYards(somevalue);
  conversionFunction[yards][feet]=yardsToFeet...
  ...
  </code></pre>
  
  <p>What am I missing as regards function pointers and arrays?</p>