title: How to make a plugin interface for a C program
body: <p>I'm looking for a way to create a plugin interface for a C program. In the interest of a short and concise example, let's say I have the following program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int complexFunction(int a, int b) { return a+b; }
  int main() {
      int a = 3;
      int b = 6;
      printf("The result of C(a, b) is %d.\n", complexFunction(a, b));
      return 0;
  }
  </code></pre>
  
  <p>Instead of using the defined <code>complexFunction</code> however, I would like to allow the user to code their own and then plug-in their implementation.</p>
  
  <p>I have never worked with plugin implementations myself, but so far I have been able to come up with the following possibilities for a plugin interface:</p>
  
  <ol>
  <li>Create a 'mini scripting language' which my program can parse and create a procedure pipeline for, then pass the variables into that pipeline. This would involve a lot of 'generic' functions for each possible action in the scripting language.</li>
  <li>Use a pre-existing scripting language for the same purpose (however this may not be possible as I would need some very specialised scriptable functions).</li>
  <li>Allow the user to write and compile a C file containing the definition of <code>complexFunction(int, int)</code>, and dynamically load that at run-time. This is the least secure option but for development purposes it would be ideal as (only) I would author my own plugins and I could dynamically add functionality to my program.</li>
  </ol>
  
  <p>My question is twofold:</p>
  
  <ul>
  <li>What are the common ways of handling plug-in capabilities in Applications?</li>
  <li>How can I accomplish <strong>(3)</strong> / is <strong>(3)</strong> even possible in C? After <code>fopen</code>-ing a file, can I somehow use it as code in the current program?</li>
  </ul>