title: setup a series function pointers and callbacks in c
body: <p>I've read a few different SO answers on function pointers as callbacks but I am still having some trouble implementing it myself.</p>
  
  <p>Questions like this: <a href="https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work">How do function pointers in C work?</a></p>
  
  <p>and this: <a href="https://stackoverflow.com/questions/1591361/understanding-typedefs-for-function-pointers-in-c-examples-hints-and-tips-ple">Understanding typedefs for function pointers in C</a></p>
  
  <p>and a few others.</p>
  
  <p>I am not sure if this is the best way to go about it.</p>
  
  <p>file.h</p>
  
  <pre><code>typedef int (*reg_callback)(void*, void*); //generalize a bit?
  
  int register_created(reg_callback cb);
  int register_fixed_update(reg_callback cb);
  int register_variable_update(reg_callback cb);
  int register_render(reg_callback cb);
  int register_pased(reg_callback cb);
  int register_resume(reg_callback cb);
  int register_resize(reg_callback cb);
  int register_quit(reg_callback cb);
  
  int init_engine(int width, int height, char *title, double fps);
  
  //prototypes of functions that I need callbacks for atm maybe more soon
  void created(void);
  void fixed_update(void);
  void variable_update(void);
  void render(double alpha);
  void paused(void);
  void resumed(void);
  void resized(int width, int height);
  void quit(void);
  </code></pre>
  
  <p>file.c</p>
  
  <pre><code>static int register_callback_function(int c_type, reg_callback cb)
  {
      int success = -1;
      switch(c_type)
      {
          case 000000:
              printf("registering fixed update\n");
              break;
          case 000001:
              printf("registering variable update\n");
              break;
          case 000002:
              printf("registering render\n");
              break;
          case 000003:
              printf("registering pause\n");
              break;
          case 000004:
              printf("registering resume\n");
              break;
          case 000005:
              printf("registering resize\n");
              break;
          case 000006:
              printf("registering quit\n");
              break;
          default:break;
      }
      return success;
  }
  int register_fixed_update(reg_callback cb)     { return register_callback_function(000000, cb); };
  int register_variable_update(reg_callback cb)  { return register_callback_function(000001, cb); };
  int register_render(reg_callback cb)           { return register_callback_function(000002, cb); };
  int register_pased(reg_callback cb)            { return register_callback_function(000003, cb); };
  int register_resume(reg_callback cb)           { return register_callback_function(000004, cb); };
  int register_resize(reg_callback cb)           { return register_callback_function(000005, cb); };
  int register_quit(reg_callback cb)             { return register_callback_function(000006, cb); };
  int register_created(reg_callback cb)          { return register_callback_function(000007, cb); };
  
  void created(void)                  { //call create callback func }
  void fixed_update(void)             { //call fixed update callback func}
  void variable_update(void)          { //...}
  void render(double alpha)           { //...}
  void paused(void)                   { //...}
  void resumed(void)                  { //...}
  void resized(int width, int height) { //...}
  void quit(void)                     { //...}
  </code></pre>
  
  <p>currently I am getting a warning like these:</p>
  
  <pre><code>warning: incompatible pointer types passing 'void (void)' to parameter of
        type 'reg_callback' (aka 'int (*)(void *, void *)') [-Wincompatible-pointer-types]
      register_created(created);
                       ^~~~~~~
  note: passing argument to parameter 'cb' here
  int register_created(reg_callback cb);
  </code></pre>
  
  <p>incompatibile pointer types but I though that void* pointers could point to anything, even nothing?</p>
  
  <p>I wanted to generalize the function pointer so that I could just use the one pointer prototype to handle all this setup code. From the code not working I know I am going about it the wrong way and would like to fix that.</p>
  
  <p>maybe have a struct with some pointer to functions but I am not sure atm.</p>