Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jul 2002 14:47:45 +0100 (BST)
From:      Richard Tobin <richard@cogsci.ed.ac.uk>
To:        Terry Lambert <tlambert2@mindspring.com>, Luigi Rizzo <luigi@FreeBSD.ORG>
Cc:        Mike Barcroft <mike@FreeBSD.ORG>, current@FreeBSD.ORG
Subject:   Re: different packing of structs in kernel vs. userland ?
Message-ID:  <200207151347.OAA24437@rhymer.cogsci.ed.ac.uk>
In-Reply-To: Terry Lambert's message of Mon, 15 Jul 2002 04:24:33 -0700

next in thread | raw e-mail | index | archive | help
> 	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,

Er, no, that's not right.  Otherwise 

  fee = malloc(n * sizeof(struct foo))

wouldn't work.

C89 says:

  There may also be unnamed padding at the end of a structure or union,
  as necessary to achieve the proper alignment were the structure or
  union to be an element of an array.

And:

  the result [of sizeof] is the total number of bytes in such an object,
  including internal and trailing padding.

So if a struct needs padding in an array, it has it even when it isn't
in an array.

-- 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?200207151347.OAA24437>