This is wat i read.........The total no. of bytes allocated is 10 and not 12 bytes..in case if  32 bits is the word boundary. Bcos the 22 bits of op2 will be allocated with in the 4bytes of integer.....Then 1 byte of padding occurs for char, then followed by 4 bytes for integer....
so totally 4+1+1+4= 10 bytes.........
PLZZ do share ur comments....Agree/Disagree.....Ur Ideas........


Ravi Pandit <[EMAIL PROTECTED]> wrote:

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]





Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.

To unsubscribe : [EMAIL PROTECTED]




Yahoo! Groups Sponsor
ADVERTISEMENT
click here
Web Bug from http://us.adserver.yahoo.com/l?M=298184.5639630.6699735.3001176/D=groups/S=:HM/A=2434971/rand=351968892


Yahoo! Groups Links

Reply via email to