From owner-freebsd-hackers Sun Nov 2 08:32:27 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id IAA29121 for hackers-outgoing; Sun, 2 Nov 1997 08:32:27 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from Campino.Informatik.RWTH-Aachen.DE (campino.Informatik.RWTH-Aachen.DE [137.226.116.240]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id IAA29112 for ; Sun, 2 Nov 1997 08:32:23 -0800 (PST) (envelope-from kuku@gilberto.physik.RWTH-Aachen.DE) Received: from gil.physik.rwth-aachen.de (gilberto.physik.rwth-aachen.de [137.226.30.2]) by Campino.Informatik.RWTH-Aachen.DE (8.8.7/RBI-Z14) with ESMTP id RAA22543; Sun, 2 Nov 1997 17:32:20 +0100 (MET) Received: (from kuku@localhost) by gil.physik.rwth-aachen.de (8.8.5/8.6.9) id RAA05051; Sun, 2 Nov 1997 17:47:10 +0100 (MET) Message-ID: <19971102174709.12838@gil.physik.rwth-aachen.de> Date: Sun, 2 Nov 1997 17:47:09 +0100 From: Christoph Kukulies To: John Milford Cc: Christoph Kukulies , freebsd-hackers@freefall.freebsd.org Subject: Re: gcc and bitfields References: <199711021618.IAA02063@soda.CSUA.Berkeley.EDU> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.81e In-Reply-To: <199711021618.IAA02063@soda.CSUA.Berkeley.EDU>; from John Milford on Sun, Nov 02, 1997 at 08:18:29AM -0800 Sender: owner-freebsd-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk On Sun, Nov 02, 1997 at 08:18:29AM -0800, John Milford wrote: > Christoph Kukulies 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