title: function pointer with variable inputs
body: <p>In C, I am trying to pass a single-variable function into an optimization routine (<code>optimization_routine</code>). The optimization routine takes as input a pointer <code>func1ptr</code> to a function of a single <code>float</code> variable. However, I need to be able to pass multiple variables into this function. Thus, I am trying to construct a function pointer of one variable where all but the first inputs are "constants" into the function variable (sort of analogous to a partial derivative in calculus). I think I can do this with function pointers, but I can't figure out a syntax that makes sense.</p>
  
  <p>That is, I have a function like this:</p>
  
  <pre><code>float function_all_inputs( float A, int B, float C, char D);
  </code></pre>
  
  <p>The optimization function requires a pointer like this:</p>
  
  <pre><code>typedef (*func1ptr)(float);
  void optimization_function( func1ptr fp );
  </code></pre>
  
  <p>Thus, I want to construct a function of this form:</p>
  
  <pre><code>// create a function of A only at runtime using inputs B,C,D
  func1ptr fp = ( &amp; function_all_inputs(A,B,C,D))(A);  
  </code></pre>
  
  <p>The function pointed to by <code>fp</code> should have the signature:</p>
  
  <pre><code>float function_one_input(float A);
  </code></pre>
  
  <p>Inputs B, C, and D are calculated elsewhere in the code, and thus are not known at compile-time; however, they are constant inside <code>optimization_function</code>.</p>
  
  <p>I think I can do this in pure C using function pointers, however, I can't figure out the correct syntax. None of the examples I found online cover this case. Any advice you can provide would be appreciated.</p>