bytes packing for char type

  • Follow


Hi guys, =)

I am doing a little experiment, and I found that this is really
interesting, but I don't know, can anyone please tell me why is that?
I've defined a structure like this

typedef struct myA
{
     char c1[5];

} mya

if I send this structure from a Linux platform to a Win32 platform, it
requires 8 bytes ( yea , some how it packes 4 bytes a unit, if c1 is 3
bytes, then it sends 4 bytes for total. It does make sense for me. )

However, If I do something like this.

typedef struct myB
{
     char d1[5], d2[5];  //(they both assign the value to "abcd")
     int d3 = 0;

} myb

And

typedef struct myBB
{
     char d4[5]; //(assign the value to "abcd")
     char d5[5]; //(assign the value to "abcd")
     int d6 = 0;

} mybb

somehow, in myb the data in d2 will shift to d3 ( no more contains
zero value ), but in mybb, they all contain its only value.
pretty wried. =)

thanks for telling me the answer guys =)

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply tikviva 7/27/2004 10:58:57 AM


0 Replies
92 Views

(page loaded in 0.026 seconds)

Similiar Articles:













7/19/2012 8:08:34 PM


Reply: