title: Is it good practice to cast a pointer to a member function as a pointer to a C function
body: <p>This code compiles (with g++ (GCC) 6.3.1) and appears to "work". But I'm VERY skeptical as to whether it constitutes <strong><em>good practice</em></strong>.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;pthread.h&gt;
  
  
  class ThreadObj
  {
    public:
      void *memberFunction(void*);
      void startThread(void);
    static int w;
  };
  
  int ThreadObj::w = 13;
  
  void* ThreadObj::memberFunction(void*)
  {
    w = 17;
    return 0;
  }
  
  void  ThreadObj::startThread(void)
  {
    void * (*p)(void *) = *((void * (*)(void *))&amp;ThreadObj::memberFunction);
    pthread_t    tid;
  
    if (pthread_create(&amp;tid, 0, p, this) == 0)
      pthread_detach(tid);
  }
  
  int main(int argc, char *argv[] )
  {
    ThreadObj thr;
    thr.startThread();
  
    return 0;
  }
  </code></pre>
  
  <p>Casting a pointer to a member function as a pointer to a C function and passing <code>this</code> as data seems to rely (TOO MUCH) upon the mercies of how the compiler chooses to interpret/compile this.</p>
  
  <p>This has been covered before but not definitively answered.</p>
  
  <p>How can this example be broken?</p>