title: Is there any way to control the padding between struct members (incl. bit field) in C++?
body: <p>I'm working on parsing network data stream, I'm wondering if there is any way I can map the data stream directly to the data structure.</p>
  
  <p>For example, I want to define the data structure for an RTP protocol as follows.</p>
  
  <pre><code>class RTPHeader
  {
     int version:2; // The first two bits is version.
     int P:1;  // The next bits is an field P.
     int X:1;
     int CC:4;
     int M:1;
     int PT:7;
     int sequenceNumber;
     int64 timestamp;
     .....
  };
  </code></pre>
  
  <p>And using it this way.</p>
  
  <pre><code>RTPHeader header;
  memcpy(&amp;header, steamData, sizeof(header));
  </code></pre>
  
  <p>But as the C++ compiler will insert padding between the members, is there any way to control that so that no padding are added between members (including the bit field members)?</p>
  
  <p>This question is NOT a duplicate of <a href="https://stackoverflow.com/questions/3277842/how-to-get-rid-of-padding-bytes-between-data-members-of-a-struct">How to get rid of padding bytes between data members of a struct</a> because there can be bit fields in my example.</p>