https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82105

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Dudu from comment #7)
> By the way: if you use long instead of int - you get no padding between x
> and y, so the size of the struct is smaller!!!
> 
> typedef struct {
>       unsigned long x:16;
>       unsigned long y:17;
>       unsigned short z;
> } SizeofThisIs8;
> 
> typedef struct {
>       unsigned int x:16;
>       unsigned int y:17;
>       unsigned short z;
> } SizeofThisIs12;
> 
> Is this really the expected behavior???

Yes.  Basically in the first case, long is 64bits so 16+17 <=64 while int is 32
since 16+17 > 32, the 17 bit-field has to go to the next 32bit unit.

Reply via email to