Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jul 2002 14:57:35 +0200
From:      Thomas Moestl <tmoestl@gmx.net>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        Luigi Rizzo <luigi@FreeBSD.org>, Mike Barcroft <mike@FreeBSD.org>, current@FreeBSD.org
Subject:   Re: different packing of structs in kernel vs. userland ?
Message-ID:  <20020715125735.GC314@crow.dom2ip.de>
In-Reply-To: <3D32B0F1.27EA45EE@mindspring.com>
References:  <20020714011810.A72236@iguana.icir.org> <20020714203642.GD314@crow.dom2ip.de> <20020714230821.C64412@espresso.q9media.com> <20020715105158.GA314@crow.dom2ip.de> <20020715040008.A85276@iguana.icir.org> <3D32B0F1.27EA45EE@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 2002/07/15 at 04:24:33 -0700, Terry Lambert wrote:
> Luigi Rizzo wrote:
> > sorry but all this just does not make sense to me.
> > 
> > sizeof(foo) should give the same result irrespective of
> > where you use it.
> > 
> > Perhaps the best thing would be to put a
> > 
> >         printf("struct ip_fw has size %d\n", sizeof(struct ip_fw));
> > 
> > both in ipfw2.c and somewhere in ip_fw2.c and see if there is
> > a mismatch between the two numbers.
> 
> I have to assume that what didn't make sense was that his patch
> worked?  8-).
> 
> He's making the valid point that for:
> 
> 	struct foo *fee;
> 
> It's possible that:
> 
> 	sizeof(struct foo) != (((char *)&fee[1]) - ((char *)&fee[0]))

No, I do not. In fact, the opposite:

 	sizeof(struct foo) = (((char *)&fee[1]) - ((char *)&fee[0]))

_must_ always be true, since it is legal to compute the size of
storage needed for an n-element array of struct foo by using
(sizeof(struct foo) * n).

My point was that, because of the above, any padding that might be
required between the first and last member of two struct foo's
immediately following each other must be _included_ in struct foo,
after the last element.

	- thomas

-- 
Thomas Moestl <tmoestl@gmx.net>	http://www.tu-bs.de/~y0015675/
              <tmm@FreeBSD.org>	http://people.FreeBSD.org/~tmm/
PGP fingerprint: 1C97 A604 2BD0 E492 51D0  9C0F 1FE6 4F1D 419C 776C

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?20020715125735.GC314>