title: C programming structure passed as cast to char *?
body: <p>I have a little problem, in a scenario where: </p>
  
  <pre><code>while (read(dp-&gt;fd, (char *) &amp;dirbuf, sizeof(dirbuf)) == sizeof(dirbuf)) { ... }
  </code></pre>
  
  <p>where dirbuf is:</p>
  
  <pre><code>struct direct dirbuf { 
      ino_t d_ino; char d_name[DIRSIZ]; 
  };  
  </code></pre>
  
  <p>How does C know to read in data contingently into our structure? With the read() Like, the alignment of our dirbuf fits perfectly as a character array? since read accepts a void * for its second argument, passing a structure as a cast to char * makes very little sense to me, how does it cater for other member elements properly?</p>
  
  <p>I'm not sure if I'm even asking this question properly, I hope someone can decipher my problem behind my lunacy and help me out.</p>
  
  <p>Thanks.</p>