From owner-freebsd-hackers Sun Nov 2 14:13:36 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id OAA15010 for hackers-outgoing; Sun, 2 Nov 1997 14:13:36 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from unix.tfs.net (root@unix.tfs.net [199.79.146.60]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id OAA15004 for ; Sun, 2 Nov 1997 14:13:33 -0800 (PST) (envelope-from jbryant@argus.tfs.net) Received: from argus.tfs.net (pm3-p21.tfs.net [206.154.183.213]) by unix.tfs.net (8.8.5/8.8.5) with ESMTP id QAA17145; Sun, 2 Nov 1997 16:11:58 -0600 Received: (from jbryant@localhost) by argus.tfs.net (8.8.7/8.8.5) id QAA00245; Sun, 2 Nov 1997 16:13:21 -0600 (CST) From: Jim Bryant Message-Id: <199711022213.QAA00245@argus.tfs.net> Subject: Re: gcc and bitfields In-Reply-To: <199711021618.IAA02063@soda.CSUA.Berkeley.EDU> from John Milford at "Nov 2, 97 08:18:29 am" To: jwm@CSUA.Berkeley.EDU (John Milford) Date: Sun, 2 Nov 1997 16:13:20 -0600 (CST) Cc: freebsd-hackers@freebsd.org Reply-to: jbryant@tfs.net X-Windows: R00LZ!@# MS-Winbl0wz DR00LZ!@# X-Operating-System: FreeBSD 2.2.2-RELEASE #0: Wed Jul 9 01:01:24 CDT 1997 X-Mailer: ELM [version 2.4ME+ PL31H (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk In reply: > 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. 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+