Date: Mon, 15 Jul 2002 15:31:22 -0700 From: Terry Lambert <tlambert2@mindspring.com> To: Richard Tobin <richard@cogsci.ed.ac.uk> Cc: current@FreeBSD.ORG Subject: Re: different packing of structs in kernel vs. userland ? Message-ID: <3D334D3A.DA728FAC@mindspring.com> References: <200207152212.XAA12604@rhymer.cogsci.ed.ac.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D334D3A.DA728FAC>