From owner-freebsd-hackers Sun Nov 2 08:18:59 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id IAA28534 for hackers-outgoing; Sun, 2 Nov 1997 08:18:59 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from soda.CSUA.Berkeley.EDU (soda.CSUA.Berkeley.EDU [128.32.43.52]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id IAA28529 for ; Sun, 2 Nov 1997 08:18:56 -0800 (PST) (envelope-from jwm@soda.CSUA.Berkeley.EDU) Received: from soda.CSUA.Berkeley.EDU (jwm@localhost) by soda.CSUA.Berkeley.EDU (8.6.12/8.6.12) with ESMTP id IAA02063; Sun, 2 Nov 1997 08:18:46 -0800 Message-Id: <199711021618.IAA02063@soda.CSUA.Berkeley.EDU> To: Christoph Kukulies Cc: freebsd-hackers@freefall.freebsd.org Subject: Re: gcc and bitfields In-reply-to: Message from Christoph Kukulies of "Sun, 02 Nov 1997 16:31:07 +0100." <199711021531.QAA04864@gil.physik.rwth-aachen.de> Date: Sun, 02 Nov 1997 08:18:29 -0800 From: John Milford Sender: owner-freebsd-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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)); --John