title: C function pointer casting to void pointer
body: <p>I am trying to run the following program but getting some strange errors:</p>
  
  <p>File 1.c:</p>
  
  <pre><code>typedef unsigned long (*FN_GET_VAL)(void);
  
  FN_GET_VAL gfnPtr;
  
  void setCallback(const void *fnPointer)
  {
      gfnPtr = *((FN_GET_VAL*) (&amp;fnPointer));
  }
  </code></pre>
  
  <p>File 2.c:</p>
  
  <pre><code>extern FN_GET_VAL gfnPtr;
  
  unsigned long myfunc(void)
  {
      return 0;
  }
  
  main()
  {
     setCallback((void*)myfunc);
     gfnPtr(); /* Crashing as value was not properly 
                  assigned in setCallback function */
  }
  </code></pre>
  
  <p>Here the gfnPtr() is crashing on 64-Bit suse linux when compiled with gcc. But it successfully calling gfnPtr() VC6 and SunOS.</p>
  
  <p>But if I change the function as given below, it is working successfully. </p>
  
  <pre><code>void setCallback(const void *fnPointer)
  {
      int i; // put any statement here
      gfnPtr = *((FN_GET_VAL*) (&amp;fnPointer));
  }
  </code></pre>
  
  <p>Please help with the cause of problem. Thanks.</p>