From owner-cvs-src@FreeBSD.ORG Mon Nov 13 11:00:26 2006 Return-Path: X-Original-To: cvs-src@FreeBSD.org Delivered-To: cvs-src@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DF46D16A415; Mon, 13 Nov 2006 11:00:26 +0000 (UTC) (envelope-from bde@zeta.org.au) Received: from mailout2.pacific.net.au (mailout2-3.pacific.net.au [61.8.2.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5239043D45; Mon, 13 Nov 2006 11:00:26 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.2.162]) by mailout2.pacific.net.au (Postfix) with ESMTP id 4753350913B; Mon, 13 Nov 2006 22:00:24 +1100 (EST) Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailproxy1.pacific.net.au (Postfix) with ESMTP id 9A0858C06; Mon, 13 Nov 2006 22:00:23 +1100 (EST) Date: Mon, 13 Nov 2006 22:00:22 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Poul-Henning Kamp In-Reply-To: <3801.1163410519@critter.freebsd.dk> Message-ID: <20061113214928.P76443@delplex.bde.org> References: <3801.1163410519@critter.freebsd.dk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Joseph Koshy , src-committers@FreeBSD.org, cvs-all@FreeBSD.org, cvs-src@FreeBSD.org Subject: Re: cvs commit: src/include ar.h X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Nov 2006 11:00:27 -0000 On Mon, 13 Nov 2006, Poul-Henning Kamp wrote: > In message <20061113173927.Q75708@delplex.bde.org>, Bruce Evans writes: >> On Mon, 13 Nov 2006, Joseph Koshy wrote: >> >>> jkoshy 2006-11-13 04:28:29 UTC >>> >>> FreeBSD src repository >>> >>> Modified files: >>> include ar.h >>> Log: >>> Attempt to improve application portability by marking `struct ar_hdr' >>> as `packed'. >>> ... > > I agree with bruce that __packed is not the way to go. > > For things that represent communication protocols, even if > they happen through files, I advocate using the functions > in sys/endian.h to explicitly decode and encode fields into > bytestrings. But already uses byte strings for everything. It just requires no padding between the byte strings (so that the offsets are constant), and no padding at the end (so that offsets are constant if the struct is contained in another struct that is at least as careful about padding an aligment). BTW, you are responsible for the __packed in . Please remove it. The __CTASSERT() is enough to detect if heroic packing is ever needed. The only danger is if something has grown to depend on __packed reducing alignment as a side effect. E.g., suppose we had a byte string containing a bytewise copy of a struct ip. If the copy might be misaligned, then it should be copied to an actual struct ip before accessing it as a struct, but code that accesses it directly using ((struct ip *)&bs[N]) would work now due to the reduced alignment. Places that really need __packed should probably use __aligned() to restore the natural alignment. Bruce