title: How to cast void* to a function pointer?
body: <p>I am using xTaskCreate in FreeRTOS whose 4th parameter (void * const) is the parameter to pass to the function invoked by the new Thread.</p>
  
  <pre><code>void __connect_to_foo(void * const task_params) {
     void (*on_connected)(void);
     on_connected = (void) (*task_params);
     on_connected();
  }
  
  void connect_to_foo(void (*on_connected)(void)) {
     // Start thread
     xTaskCreate(
           &amp;__connect_to_foo,
           "ConnectTask",
           STACK_SIZE,
           (void*) on_connected, // params
           TASK_PRIORITY,
           NULL // Handle to the created Task - we don't need it.
           );
  }
  </code></pre>
  
  <p>I need to be able to pass in a function pointer with signature</p>
  
  <blockquote>
    <p>void bar();</p>
  </blockquote>
  
  <p>But I can't work out how to cast void* to a function pointer that I can invoke. Closest I can get is:</p>
  
  <blockquote>
    <p>error: 'void*' is not a pointer-to-object type on line 3</p>
  </blockquote>
  
  <p>How can I cast task_params to a function pointer that I can invoke?</p>
  
  <p>NB the code above is grossly simplified.</p>