Date: Sun, 2 Nov 1997 17:47:09 +0100 From: Christoph Kukulies <kuku@gilberto.physik.RWTH-Aachen.DE> To: John Milford <jwm@CSUA.Berkeley.EDU> Cc: Christoph Kukulies <kuku@gilberto.physik.RWTH-Aachen.DE>, freebsd-hackers@freefall.freebsd.org Subject: Re: gcc and bitfields Message-ID: <19971102174709.12838@gil.physik.rwth-aachen.de> In-Reply-To: <199711021618.IAA02063@soda.CSUA.Berkeley.EDU>; from John Milford on Sun, Nov 02, 1997 at 08:18:29AM -0800 References: <kuku@gilberto.physik.RWTH-Aachen.DE> <199711021618.IAA02063@soda.CSUA.Berkeley.EDU>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Nov 02, 1997 at 08:18:29AM -0800, John Milford wrote: > 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. > > > > 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 tried that already to no avail. struct C_OPEN { int a; int b; unsigned xtd:1; unsigned reserved:15; } __attribute__ ((packed)); main() { printf("sizeof struct C_OPEN = %d\n", sizeof (struct C_OPEN)); } $ ./a.out 12 Ah, I found it: making the bitfield declarations unsigned short works. > > > > --John -- Chris Christoph P. U. Kukulies kuku@gil.physik.rwth-aachen.de
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19971102174709.12838>