title: Which data type to be used for a "generic" function pointer?
body: <p>According to the answers to various questions on this web site (<a href="https://stackoverflow.com/questions/26917194/can-void-be-used-to-store-function-pointers">link</a>, <a href="https://stackoverflow.com/questions/1096341/function-pointers-casting-in-c">link</a>, <a href="https://stackoverflow.com/questions/12358843/why-are-function-pointers-and-data-pointers-incompatible-in-c-c">link</a>), it is not allowed to cast a function pointer to a data pointer.</p>
  <p>This makes sense to me because there are some CPU architectures where a function pointer is longer than a data pointer: By casting a function pointer to a data pointer, data will get lost.</p>
  <p>A historic example for desktop programs would be x86-16 with &quot;medium&quot; memory layout (<code>sizeof(void (*)())=4</code>, <code>sizeof(void *)=2</code>); you still find this behavior in some modern (mainly non-desktop) CPUs.</p>
  <p>If a variable shall hold a pointer to &quot;unknown&quot; data, you use the data type <code>void *</code>.</p>
  <p>I'm currently writing a program where a variable may hold a pointer to an &quot;unknown&quot; function (just like the value returned by <code>dlsym()</code> in Linux or <code>GetProcAddress()</code> in Windows):</p>
  <pre><code>// ---- file1.c ----
  
  typedef /* What to use here? */ functionPointer;
  ...
  functionPointer myPointer, myPointer2;
  myPointer = getFunction(1);
  myPointer2 = getFunction(2);
  ...
  double (*fptr)(double, void *) = myPointer2;
  ...
  
  // ---- file2.c ----
  
  void func1(void);
  double func2(double x, void * y);
  
  functionPointer getFunction(int which)
  {
      switch(which)
      {
      case 1: return &amp;func1;
      case 2: return &amp;func2;
      ...
      }
  }
  </code></pre>
  <p>Which data type would be used in such a situation if the program should be platform independent?</p>
  <p>If there is no solution that works on all platforms (desktop, microcontrollers, DSP, GPU etc.):</p>
  <p>Is there a solution that works on all desktops?</p>