From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 7 12:19:23 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 44A0EF2A for ; Fri, 7 Dec 2012 12:19:23 +0000 (UTC) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from comsys.kpi.ua (comsys.kpi.ua [77.47.192.42]) by mx1.freebsd.org (Postfix) with ESMTP id E19818FC0C for ; Fri, 7 Dec 2012 12:19:22 +0000 (UTC) Received: from pm513-1.comsys.kpi.ua ([10.18.52.101] helo=pm513-1.comsys.ntu-kpi.kiev.ua) by comsys.kpi.ua with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1Tgwtk-0001HO-0w; Fri, 07 Dec 2012 14:19:20 +0200 Received: by pm513-1.comsys.ntu-kpi.kiev.ua (Postfix, from userid 1001) id 45C9D1CC21; Fri, 7 Dec 2012 14:19:20 +0200 (EET) Date: Fri, 7 Dec 2012 14:19:20 +0200 From: Andrey Simonenko To: Rick Macklem Subject: Re: any arch not pack uint32_t x[2]? Message-ID: <20121207121920.GA17861@pm513-1.comsys.ntu-kpi.kiev.ua> References: <886101549.1211675.1354831120890.JavaMail.root@erie.cs.uoguelph.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <886101549.1211675.1354831120890.JavaMail.root@erie.cs.uoguelph.ca> User-Agent: Mutt/1.5.21 (2010-09-15) X-Authenticated-User: simon@comsys.ntu-kpi.kiev.ua X-Authenticator: plain X-Sender-Verify: SUCCEEDED (sender exists & accepts mail) X-Exim-Version: 4.63 (build at 28-Apr-2011 07:11:12) X-Date: 2012-12-07 14:19:20 X-Connected-IP: 10.18.52.101:44477 X-Message-Linecount: 58 X-Body-Linecount: 43 X-Message-Size: 2586 X-Body-Size: 1895 Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Dec 2012 12:19:23 -0000 On Thu, Dec 06, 2012 at 04:58:40PM -0500, Rick Macklem wrote: > Hi, > > The subject line pretty well says it. I am about ready > to commit the NFSv4.1 client patches, but I had better > ask this dump question first. > > Is there any architecture where: > uint32_t x[2]; > isn't packed? (Or, sizeof(x) != 8, if you prefer.) I had similar question some time ago, so I made some research in standards and got the following information ("WG14 N1548 Committee Draft" is used for references, exact definitions can be read in sections with numbers given in parentheses). Exact-width integer type intN_t is optional and designates a signed integer type with width N, without padding bits. Implementation cannot provide some intN_t types. The width of such integer types is given in bits. (7.20.1.1) An array type describes a contiguously allocated nonempty set of objects (6.2.5). (Some compilers allow to declare empty arrays with zero size.) The sizeof operator yields the size (in bytes) of its operand. When sizeof is applied to an operand that has type char, the result is 1. The sizeof operator can be used for computing numbers of elements in an array: sizeof(array) / sizeof(array[0]) (6.5.3.4). A byte consists of contiguous sequence of bits, number of bits in a byte is implementation defined (3.6). Using this information I think that sizeof(x) is equal to (2 * sizeof(x[0])) or (2 * sizeof(uint32_t)) and occupies exactly 64 bits in memory, but it is not necessarily equal to 8, since implementation can use different numbers of bits for one byte (or char). Also I think, that if an implementation supports uint8_t, then a pointer to uint8_t can be used for accessing each of 4 octets in a data of the uint32_t type. Please, correct these statements if they are wrong. There are "Everything you ever wanted to know about C types" series, that are related to this question.