From owner-freebsd-hackers@FreeBSD.ORG Sun Oct 10 23:48:29 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B919416A4CE for ; Sun, 10 Oct 2004 23:48:29 +0000 (GMT) Received: from whisker.bluecoat.com (whisker.bluecoat.com [216.52.23.28]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9F9F243D49 for ; Sun, 10 Oct 2004 23:48:29 +0000 (GMT) (envelope-from qing.li@bluecoat.com) Received: from bcs-mail.bluecoat.com (bcs-mail.bluecoat.com [216.52.23.69]) by whisker.bluecoat.com (8.13.0/8.13.0) with ESMTP id i9ANmHBj020354; Sun, 10 Oct 2004 16:48:17 -0700 (PDT) X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Sun, 10 Oct 2004 16:48:17 -0700 Message-ID: <00CDF9AA240E204FA6E923BD35BC643606BF695A@bcs-mail.internal.cacheflow.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Bit field definition ? Thread-Index: AcSto0HA7MChXlkPSNiy3UudDGqXrQBfoNag From: "Li, Qing" To: "Dan Nelson" X-Scanned-By: MIMEDefang 2.44 cc: freebsd-hackers@freebsd.org Subject: RE: Bit field definition ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Oct 2004 23:48:29 -0000 >=20 > In the last episode (Oct 08), Li, Qing said: > > The bit fields "th_x2" and "th_off" in "struct tcphdr", > > even though defined as "u_int", actually occupies 1 byte. >=20 > u_int th_x2:4, /* (unused) */ > th_off:4; /* data offset */ >=20 > The :4 after each variable means 4 bits long, so both fields=20 > together take up 8 bits =3D 1 byte. That's the whole purpose=20 > of bitfields :) >=20 =09 D'oh I didn't ask the right question. It seems u_int specifies the packing and alignment size for the bit fields, is that correct ? struct { u_int a:4, =20 b:4; }; is 4 bytes in size. struct { u_int a:4, b:4; short c; }; is 4 bytes in size. struct { u_int a:4, b:4; short c; u_char d; }; is 8 bytes in size; But struct { u_int a:4, b:4; u_char d; short c; }; is 4 bytes in size; -- Qing