From owner-freebsd-current Mon Jul 15 15:32:29 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B29F737B400 for ; Mon, 15 Jul 2002 15:32:25 -0700 (PDT) Received: from hawk.mail.pas.earthlink.net (hawk.mail.pas.earthlink.net [207.217.120.22]) by mx1.FreeBSD.org (Postfix) with ESMTP id 47C4B43E31 for ; Mon, 15 Jul 2002 15:32:25 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from pool0196.cvx21-bradley.dialup.earthlink.net ([209.179.192.196] helo=mindspring.com) by hawk.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 17UEOC-0006Dg-00; Mon, 15 Jul 2002 15:32:21 -0700 Message-ID: <3D334D3A.DA728FAC@mindspring.com> Date: Mon, 15 Jul 2002 15:31:22 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Richard Tobin Cc: current@FreeBSD.ORG Subject: Re: different packing of structs in kernel vs. userland ? References: <200207152212.XAA12604@rhymer.cogsci.ed.ac.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Richard Tobin wrote: > It is not a valid point that it's possible that > > sizeof(struct foo) != (((char *)&fee[1]) - ((char *)&fee[0])) > > because it isn't possible. It must be the case that > > sizeof(struct foo) == (((char *)&fee[1]) - ((char *)&fee[0])) > > If that's what you meant, you seem to be saying the opposite. I guess I should have been clearer; reading it again, it's clearly a double entendre on my part. Sorry for the confusion it caused. > > and that inter-structure padding depends on ordering of elements > > Yes, though it isn't "inter-structure" padding, it's padding that > is part of the structure. Yes, because the compiler can't know that a pointer will not have arithmatic done on it, because it can't know whether the element it points to is the first in a series, or only a single element. This is the source of the confusion in the size test that was broken in the case that started this thread. > > (for a good example of this, see the struct direct name element > > reference macro, which is also padding independent). > > Not sure which macro you mean here, since there are several variants > of it which work in different ways. The one in dirent.h (I'm looking > at 4.6 here) subtracts from sizeof, while the one in ufs/dir.h uses > &(0->d_name) which is equivalent to offsetof. This is the one (n.b: there didn't used to be an "offsetof"). > > Basically, end-padding happens because arrays of structures need to > > have their first element properly aligned, so there is a pad added > > after each element to ensure that the following element starts on > > an alignment boundary. > > The point is that there isn't a pad *after* each element. The pad is > part of the element, and is there regardless of whether the structure > is in an array. Again, if that's what you meant you seem to be saying > the opposite! I think I just used ambiguous language in the initial part, and that threw off everything after it. Like the SNL joke "You can't put too much water in a nuclear reactor". -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message