Date: Sun, 2 Nov 1997 16:13:20 -0600 (CST) From: Jim Bryant <jbryant@unix.tfs.net> To: jwm@CSUA.Berkeley.EDU (John Milford) Cc: freebsd-hackers@freebsd.org Subject: Re: gcc and bitfields Message-ID: <199711022213.QAA00245@argus.tfs.net> In-Reply-To: <199711021618.IAA02063@soda.CSUA.Berkeley.EDU> from John Milford at "Nov 2, 97 08:18:29 am"
index | next in thread | previous in thread | raw e-mail
In reply:
> Christoph Kukulies <kuku@gilberto.physik.RWTH-Aachen.DE> wrote:
>
> >
> > During porting a piece of a DOS program to make a driver
> > for FreeBSD of it for a certain device I'm stuck at the
> > point where there is a structure:
> >
> > struct C_OPEN {
> > int a;
> > int b;
> > unsigned xdt:1;
> > unsigned reserved:15;
> > }
> >
> > The sizeof this structure is 10 under DOS (borland C)
> > and evaluates to 12 under cc (gcc) on FreeBSD.
ahem, DOG should show 6 bytes.
> > There are a lot of these definitions and it would be
> > tedious to find a workaround.
> >
> > Does anyone know if I can pack the structure respectively
> > enforce the bitfield to a short int?
>
> By default gcc pads structures to make make the size a multiple of 4 bytes.
> Try:
>
> struct C_OPEN {
> int a;
> int b;
> unsigned xdt:1;
> unsigned reserved:15;
> } __attribute__ ((packed));
i didn't know about this...
but it will still not solve his problem...
sizeof(struct C_OPEN) will still == 12.
under MS-DOG, sizeof(int || unsigned) == 2.
which is strange, because his sizing above should actually show 6
under DOG.
since he apparently uses 16 bits in the bitfield, I can assume that to
be a short.
thus:
> struct C_OPEN {
> int a;
> int b;
> unsigned short xdt:1; /* note addition of short */
> unsigned short reserved:15; /* note addition of short */
> } __attribute__ ((packed));
should work.
jim
--
All opinions expressed are mine, if you | "I will not be pushed, stamped,
think otherwise, then go jump into turbid | briefed, debriefed, indexed, or
radioactive waters and yell WAHOO !!! | numbered!" - #1, "The Prisoner"
------------------------------------------------------------------------------
Inet: jbryant@tfs.net AX.25: kc5vdj@wv0t.#neks.ks.usa.noam grid: EM28pw
voice: KC5VDJ - 6 & 2 Meters AM/FM/SSB, 70cm FM. http://www.tfs.net/~jbryant
------------------------------------------------------------------------------
HF/6M/2M: IC-706-MkII, 2M: HTX-212, 2M: HTX-202, 70cm: HTX-404, Packet: KPC-3+
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199711022213.QAA00245>
