title: Is it a bad idea to create a generic "function pointer" union in C?
body: <p>For a project I'm working on, it's desirable to have a generic &quot;pointer to a function&quot; type. However, in C, to have a pointer to a function, you need to specify the prototype in the type of the function pointer.</p>
  <p>For example, if I have the function <code>void setdata(short data)</code>, I can't store that in the same pointer as I would a function <code>int getdata()</code>, because their arguments and return values are different.</p>
  <p>After some lateral thinking, I came up with the following workaround:</p>
  <pre><code>typedef long (* PFL)(); /* pointer to function that returns a long... */
  typedef short (* PFI)(); /* pointer to function that returns a short... */
  typedef void (* PFV)(); /* pointer to function that returns a void... */
  typedef void (* PFVAL)(long); /* pointer to function that returns a void...
                                  but has a long argument...*/
  typedef void (* PFVAI)(short); /* pointer to function that returns a void...
                                  but has an short argument...*/
  typedef void (* PFVAU)(unsigned short);
  typedef void (* PFVAII)(short, short); /* same as above, but two shorts... */
  typedef void (* PFVAUU)(unsigned short, unsigned short); /* same as above, but two shorts... */
  
  typedef union {
      PFV         pfv;
      PFI         pfi;
      PFL         pfl;
      PFVAL       pfval;
      PFVAI       pfvai;
      PFVAU       pfvau;
      PFVAII      pfvaii;
      PFVAUU      pfvauu;
  } FP;
  </code></pre>
  <p>Sure enough, I'm able to initialize instances of this type like so:</p>
  <pre><code>FP funcpointer = { .pfvai = setdata };
  </code></pre>
  <p>Clang and GCC don't complain. Is this a bad idea?</p>