@kartik:
typedef struct
{
int bit1:29;
int bit2:4;
}bit;
This makes total number of bits 33, which is not on int boundry. (multiple
of 32 bits)
So to make it aligned on int boundry, 31 extra bits  are padded at the end
of bit2.
This makes size of struct 29 + 4 + 31 = 64 bits --> 8 bytes.
When bit1 + bit2 = multiple of 32, No need for alignment arises.

Similar example is
struct{
       int x;
       char y;
       }temp;
Here int --> 32 bits
char --> 8 bits
Total = 40 bits. Not a multiple of 32 bits thus, it is forcefully aligned
along int boundary by padding 24 bits.
If you are confused about all this, Google padding in struct.

On Wed, Aug 31, 2011 at 10:34 PM, kartik sachan <[email protected]>wrote:

> @ prateek i am still not geeting why now out put is 4
> but if we change second bit2:5 then out put again 8
> plzz explain throughly
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to