title: Assigning values to member of structures using void pointer and offset calculated
body: <p>I am trying to assign the values to members of a structure within a function which accepts the void * as an argument and then fill the data values based on the offset calculated for the  members of structure.  </p>
  
  <pre><code> typedef struct
      {
         char C_BFR_LINK[1];
         char C_TABLE_DATA[1];
         double MF_COD_BALANCE;
         char C_TYPE_DT[1];
      }ANS;
  </code></pre>
  
  <p>The Function   </p>
  
  <pre><code>void fillin( void *pp)  
  {  
  
   double* FVAR;  
   char* CVAR;  
   CVAR = pp;  
   memcpy(CVAR,"I",1);  
   CVAR = (void *)(pp + 1);  
   memcpy(CVAR,"S",1);  
   FVAR = (void *)(pp + 2);  
   *FVAR = 234.96;  
   CVAR = (void *) (pp + 10);  
    memcpy(CVAR,"Z",1);  
    return ;   
  }  
  </code></pre>
  
  <p>is responsible to fill in the values at respective offsets 1, 2, and 10.</p>
  
  <p>I am calling this function within main as below<br>
  **</p>
  
  <pre><code>int main()  
   {  
     void* p ;
    ANS ans;  
    fillin(&amp;ans);  
    return 0;  
   }
  </code></pre>
  
  <p>**  </p>
  
  <p>I debugged using gdb that within the function <strong>fillin</strong> the values gets assigned to the members but as soon as the <strong>control comes to the main program the double value is lost</strong> and it's not proper.</p>
  
  <pre><code>(gdb) p pp
  $1 = (void *) 0xffffdabc    
  (gdb) x /c 0xffffdabc  
  0xffffdabc:     73 'I'  
  (gdb) x /c 0xffffdabd    
  0xffffdabd:     83 'S'  
  (gdb) n  
  32       *FVAR = 234.96;  
  (gdb) n  
  33      CVAR = (void *) (pp + 10);  
  (gdb) **x /f 0xffffdabe**  
  0xffffdabe:     234.96000000000001  
  57       return 0;  
  (gdb) **p ans**  
  $2 = {C_BFR_LINK = "I", C_TABLE_DATA = "S",  
    **MF_COD_BALANCE = 1.9876540305898699e-268**, C_TYPE_DT = "\213"}  
  </code></pre>
  
  <p>Can Anyone help me out? This code is being built with gcc 4.4.6 20120305. Any pointers or help is very much appreciated.</p>