Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Dec 2012 14:19:20 +0200
From:      Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To:        Rick Macklem <rmacklem@uoguelph.ca>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: any arch not pack uint32_t x[2]?
Message-ID:  <20121207121920.GA17861@pm513-1.comsys.ntu-kpi.kiev.ua>
In-Reply-To: <886101549.1211675.1354831120890.JavaMail.root@erie.cs.uoguelph.ca>
References:  <886101549.1211675.1354831120890.JavaMail.root@erie.cs.uoguelph.ca>

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20121207121920.GA17861>