title: Function pointer cast to different signature
body: <p>I use a structure of function pointers to implement an interface for different backends. The signatures are very different, but the return values are almost all void, void * or int.</p>
  
  <pre><code>
  struct my_interface {
      void  (*func_a)(int i);
      void *(*func_b)(const char *bla);
      ...
      int   (*func_z)(char foo);
  };
  </code></pre>
  
  <p>But it is not required that a backends supports functions for every interface function. So I have two possibilities, first option is to check before every call if the pointer is unequal NULL. I don't like that very much, because of the readability and because I fear the performance impacts (I haven't measured it, however). The other option is to have a dummy function, for the rare cases an interface function doesn't exist.</p>
  
  <p>Therefore I'd need a dummy function for every signature, I wonder if it is possible to have only one for the different return values. And cast it to the given signature.</p>
  
  <pre><code>
  #include &lt;stdio.h&gt;
  
  int nothing(void) {return 0;}
  
  typedef int (*cb_t)(int);
  
  int main(void)
  {
      cb_t func;
      int i;
  
      func = (cb_t) nothing;
      i = func(1);
  
      printf("%d\n", i);
  
      return 0;
  }
  </code></pre>
  
  <p>I tested this code with gcc and it works. But is it sane? Or can it corrupt the stack or can it cause other problems?</p>
  
  <p>EDIT: Thanks to all the answers, I learned now much about calling conventions, after a bit of further reading. And have now a much better understanding of what happens under the hood.</p>