title: c++ casting void* to int error
body: <p>I'm rather new to C/C++ and I'm trying to use a C library that defines data structure PDS and provides methods to accessing the data.</p>
  
  <p>Here's the function I'm using to access it:</p>
  
  <pre><code>pdsGetNext  (PDS *pds,char **pKey,PDStype *pT,size_t *pS,void **pD);
  </code></pre>
  
  <p>It basically returns the key of the element, type of the element, size of the element and the actual data of the element. The <code>void **pD</code> is describes like this in documentation: "Pointer to an address, which gets the actual element.".</p>
  
  <p>I'm trying to cast the data to appropriate type as indicated by "PDStype". I'm having issues casting the data to integer, here's example code:</p>
  
  <pre><code>char *key = NULL;
  PDS_TYPE type;
  size_t size;
  void *data = NULL;
  float f;
  
  pdsRewind(myPDS);
  
  while (pdsGetNext(myPDS, &amp;key, &amp;type, &amp;size, &amp;data) == PDS_ERR_NONE) {
      switch (type) {
      case PDS_TYPE::PDS_I:
          // this is integer
          printf("INT: %d\n", *((int*)data));
          printf("INT PRINTED AS STRING: %s\n", (int*)data);
          printf("INT AS STRING: %s\n", (char*)data);
          break;
      case PDS_TYPE::PDS_PCH:
          //this is null terminated string
          printf("STRING: %s\n", (char*)data);
          break;
      default:
          break;
      }
  
  }
  </code></pre>
  
  <p>The real value of the integer is 7, the output is as follows:</p>
  
  <pre><code>INT: 55
  INT PRINTED AS STRING: 7
  INT AS STRING: 7
  </code></pre>
  
  <p>to me it would seem that the first one, that I'd like to be "7", is what would print out if I had malloced the void pointer like <code>void *ptr = (char*)malloc(sizeof(o))</code> and then tried to cast it as int like <code>*((int*)ptr)</code></p>
  
  <p>My question is: is there something I'm doing wrong here when casting it to int? as I understand it, the reason the data is returned as <code>void*</code> is to enable one to use casting in this fashion.</p>