This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Bit Field Formations
- From: "Crescioli, Phil" <Phil dot Crescioli at gd-ais dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Cc: "Crescioli, Phil" <Phil dot Crescioli at gd-ais dot com>
- Date: Fri, 21 Jan 2005 10:53:08 -0500
- Subject: Bit Field Formations
Hello all,
I'm using gcc version 3.2.2 (RedHat Linux 3.2.2-5) and am having some
questions with regard to how gcc forms bit-fields.
If I create a structure that includes bit-field definitions, how are the
bit fields assigned within a word. In the example below, is variable x1
assigned to bits 31-28 or bits 3-0? My assumption is that the fields are
assigned in order so that the example produces either:
X1:31-28, x2:27-26, x3:25-23, x4:22-18, x5:17-13, x6:12, x7:11, x8:10-6,
x9:5-0
Or
X1:3-0, x2:5-4, x3:8-6, x4:13-9, x5:18-14, x6:19, x7:20, x8:25-21,
x9:31-26
Which is correct?
typdef struct
{
double a;
double b;
short int c;
short int d;
unsigned int e;
UINT32 x1 : 4;
UINT32 x2 : 2;
UINT32 x3 : 3;
UINT32 x4 : 5;
UINT32 x5 : 5;
UINT32 x6 : 1;
UINT32 x7 : 1;
UINT32 x8 : 5;
UINT32 x9 : 6;
unsigned int f;
float g;
} TEST_STRUCT
Thanks,
Phil Crescioli
General Dynamics - Advanced Information Systems
Phil.Crescioli@gd-ais.com