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 [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to