Author: Stan Eisenstat
Subject: Re: [Cs323] Bit fields
Date: Thursday, 12 Nov 2020, 07:59:57
> Message Posted By: Unknown
>
> I am not sure if I understand bit fields correctly. Say if I have the
> following struct:
>
> typedef struct
> {
> unsigned int code : 24;
> unsigned int prefix : 24;
> char k : 8;
> } tableEntry;
>
> Then the size of it would be 7 bytes?
No, 12 bytes, as you can verify by writing a short C
program that prints the size of a variable of that type.
If you put k second rather than third, the size if 8
bytes.
=====
> And
>
> typedef struct
> {
> unsigned int code : 24;
> unsigned int prefix : 24;
> char k : 8;
> unsigned int somebool :1;
> } tableEntry;
>
> will be 8 bytes?
No, 12 bytes. If you put k second rather than third,
the size if 8 bytes.
--Stan-
PREV
INDEX
NEXT