From owner-freebsd-current Mon Jul 15 6:47:52 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2FE9D37B400; Mon, 15 Jul 2002 06:47:49 -0700 (PDT) Received: from rhymer.cogsci.ed.ac.uk (rhymer.cogsci.ed.ac.uk [129.215.144.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id B5C6443E4A; Mon, 15 Jul 2002 06:47:47 -0700 (PDT) (envelope-from richard@cogsci.ed.ac.uk) Received: (from richard@localhost) by rhymer.cogsci.ed.ac.uk (8.9.3/8.9.3) id OAA24437; Mon, 15 Jul 2002 14:47:45 +0100 (BST) Date: Mon, 15 Jul 2002 14:47:45 +0100 (BST) Message-Id: <200207151347.OAA24437@rhymer.cogsci.ed.ac.uk> From: Richard Tobin Subject: Re: different packing of structs in kernel vs. userland ? To: Terry Lambert , Luigi Rizzo In-Reply-To: Terry Lambert's message of Mon, 15 Jul 2002 04:24:33 -0700 Organization: just say no Cc: Mike Barcroft , current@FreeBSD.ORG Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > 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