Note that there are some explanatory texts on larger screens.

plurals
  1. POC struct sizes inconsistence
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/143025/how-do-i-find-the-size-of-a-struct">How do I find the size of a struct?</a><br> <a href="https://stackoverflow.com/questions/6800884/struct-varies-in-memory-size">Struct varies in memory size?</a> </p> </blockquote> <p>I am using following struct for network communication, It creates lots of unnecessary bytes in between.</p> <p>It gives different size than expected 8 Bytes.</p> <pre><code>struct HttpPacket { unsigned char x1; union { struct { unsigned char len; unsigned short host; unsigned char content[4]; } packet; unsigned char bytes[7]; unsigned long num; } </code></pre> <p>And Following gives different size even though that I am removing a field from a union</p> <pre><code>struct HttpPacket { unsigned char x1; union { struct { unsigned char len; unsigned short host; unsigned char content[4]; } packet; unsigned long num; } </code></pre> <hr> <p>Also, A more clear example</p> <pre><code>struct { unsigned char len; unsigned short host; unsigned char content[4]; } packet; </code></pre> <p>And it gives a size of 8, instead of 7. And I add one more field, It still gives the same size</p> <pre><code>struct { unsigned char EXTRAADDEDFIELD; unsigned char len; unsigned short host; unsigned char content[4]; } packet; </code></pre> <hr> <p><strong>Can someone please help on resolving this issue ?</strong> </p> <p>UPDATE: I need the format to hold while transmitting the packet, So I want to skip these paddings</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload