|
Hi,
This is my analysis. The number of bytes
assigned to the structure is 12 bytes and here's how.
Bits less than a byte are rounded off to
the nearest Word boundary. In this case, 32 bits is the word
boundary.
(sizeof(int) == 4
bytes)
int op1:5 - is
assigned 1 byte
int op2:22 - is assigned 4
bytes
char
d1 - is assigned 1 byte
int
reg - is assigned 4
bytes
Total
= 10 bytes
[Data is assigned either 1 byte or in multiples
of word size.]
Since the architecture is 32 bits
(= 4 bytes), the structure is "aligned" to a 4 byte (word)
boundary.
Total = 1+4+1+4 == 10 bytes(80 bits). There
will be 2 bytes[16 bits] of Padding,(again rounding off to the nearest word
boundary...i.e 4*3 = 12 ..the next largest multiple of 4 that is closest to 10
is 12) .Hence the number of bytes assigned would be 12.
PS: "The word size and
alignment on the machine is assumed to be 4 bytes"
Let me know any
agreements/dis-agreements.
Cheers
-Ravi
#include<stdio.h>
int main() { struct
Instruct
{
int op1:5,
op2:17; // or if op2: 22 - still doesn't
matter.....
char d1; int reg; } Instruct; printf("%d is the size of the
structure",sizeof(Instruct));
return 0; } To unsubscribe : [EMAIL PROTECTED]
Yahoo! Groups Links
|
- Re: (PT) My Analysis - Question on Structures/Bit Fiel... Ravi Pandit
- Re: (PT) My Analysis - Question on Structures/Bit... varaprasad venkata
