Byte Packing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How does the byte packing and the byte alignment work in VC++ compiler? What is the effect of #pragma pack(n) on the alignment and byte packing
for example while using the structur
struc

double a
char b
char c
}
in a 8 byte packing the sizeof structure is 16. Could anyone explain.
 
Gajendra said:
How does the byte packing and the byte alignment work in VC++
compiler? What is the effect of #pragma pack(n) on the alignment and
byte packing. for example while using the structure
struct
{
double a;

8 bytes.

1 byte

1 byte
6 bytes of padding to make the struct-size a multiple of 8. This is
necessary to ensure that in an array of structs that the 'a' member always
has 8-byte alignment.
};
in a 8 byte packing the sizeof structure is 16. Could anyone explain.

8+1+1+6=16

-cd
 
Back
Top