Date: Mon, 15 Jul 2002 23:12:08 +0100 (BST) From: Richard Tobin <richard@cogsci.ed.ac.uk> To: Terry Lambert <tlambert2@mindspring.com> Cc: current@FreeBSD.ORG Subject: Re: different packing of structs in kernel vs. userland ? Message-ID: <200207152212.XAA12604@rhymer.cogsci.ed.ac.uk> In-Reply-To: Terry Lambert's message of Mon, 15 Jul 2002 14:16:59 -0700
next in thread | raw e-mail | index | archive | help
> If everyone could read the text past my example of bad math, so > that they could know it was an intentional example of bad math, > live would be beautiful. 8-). I did read past it, and I just read it again, and I can't make it come out any way other than it did the first time. You said: > He's making the valid point that for: > > struct foo *fee; > > It's possible that: > > sizeof(struct foo) != (((char *)&fee[1]) - ((char *)&fee[0])) > > because of end-padding, which is not accounted for in arrays, 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. > 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. > (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. > 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! -- Richard 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?200207152212.XAA12604>