title: Libcurl: why curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, obj) passes my writefunction pointer, that is not equal to obj?
body: <p>It's modified example, that ships with libcurl. I pass bodyfile to function write_data by setting CURLOPT_WRITEDATA. It really writes data to file, but pointer is not equal to pointer passed to setopt(curl_handle, CURLOPT_WRITEDATA, pointer). And I get SIGSEGV if I try to pass pointer to object, other than FILE. Why? How can I pass the same pointer?</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;assert.h&gt;
  
  #include &lt;curl/curl.h&gt;
  #include &lt;curl/types.h&gt;
  #include &lt;curl/easy.h&gt;
  FILE *bodyfile;
  static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
  {
      assert(bodyfile == (FILE*) stream); //this assertion fails, but when i comment it, code works. Why?
      int written = fwrite(ptr, size, nmemb, (FILE *)stream);
      return written;
  }
  
  int main(void)
  {
      CURL *curl_handle;
      static const char *headerfilename = "head.out";
      FILE *headerfile;
      static const char *bodyfilename = "body.out";
  
      curl_global_init(CURL_GLOBAL_ALL);
  
      /* init the curl session */
      curl_handle = curl_easy_init();
  
      /* set URL to get */
      curl_easy_setopt(curl_handle, CURLOPT_URL, "http://google.com");
  
      /* no progress meter please */
      curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
  
      /* send all data to this function  */
      curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
  
      /* open the files */
      headerfile = fopen(headerfilename,"w");
      if (headerfile == NULL) {
          curl_easy_cleanup(curl_handle);
          return -1;
      }
      bodyfile = fopen(bodyfilename,"w");
      if (bodyfile == NULL) {
          curl_easy_cleanup(curl_handle);
          return -1;
      }
  
      /* we want the headers to this file handle */
      curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER, headerfile);
  
      /* we want the body to this file handle */
      curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);
  
      /* get it! */
      curl_easy_perform(curl_handle);
  
      /* close the header file */
      fclose(headerfile);
  
      /* cleanup curl stuff */
      curl_easy_cleanup(curl_handle);
  
      return 0;
  }
  </code></pre>