Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

integral (non char) types allow padding?

1 view
Skip to first unread message

Mihai Rusu

unread,
Aug 7, 2008, 10:25:44 AM8/7/08
to
Hello

I am trying to figure out if the standard allows integral type representations with padding (ie value representation != object representation).

A conforming implementation can have:
- a 32bit int and 32bit unsigned int but have the unsigned int not use the sign bit for value representation? (so INT_MAX == UINT_MAX == 2^32-1)
- a 33bit int and a 33bit unsigned int and both types have the 33th bit as padding?

By reading 3.9.1 I suppose they can have padding.

--
Dizzy

Jack Klein

unread,
Aug 7, 2008, 10:37:35 PM8/7/08
to
On Thu, 07 Aug 2008 14:25:44 +0000, Mihai Rusu <di...@1and1.ro> wrote
in comp.lang.c++:

> Hello
>
> I am trying to figure out if the standard allows integral type representations with padding (ie value representation != object representation).

Yes, all integer types except the character types may have padding.
I'm not sure why you equate that to "value representation != object
representation". The fact that some bits (padding bits) of the object
representation do not participate in the value representation does not
mean that they are arbitrary. There may be one and only one defined
object representation that is valid as a representation of a
particular value.

> A conforming implementation can have:
> - a 32bit int and 32bit unsigned int but have the unsigned int not use the sign bit for value representation? (so INT_MAX == UINT_MAX == 2^32-1)

Yes and no. Yes, an implementation can have a signed/unsigned pair
containing 32 bits and using only 31 of those bits for the unsigned
type. But no, the XXX_MAX and UXXX_MAX values for such a type would
be 2^31 - 1, not 2^32 - 1.

> - a 33bit int and a 33bit unsigned int and both types have the 33th bit as padding?

Yes, this is also possible, however unlikely.

> By reading 3.9.1 I suppose they can have padding.

Yes, all scalar types other than the three character types can have
padding, not just integer types but floating point types and pointer
types as well.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html

James Kanze

unread,
Aug 8, 2008, 5:27:00 AM8/8/08
to
On Aug 7, 4:25 pm, Mihai Rusu <di...@1and1.ro> wrote:

> I am trying to figure out if the standard allows integral type
> representations with padding (ie value representation !=
> object representation).

> A conforming implementation can have:
> - a 32bit int and 32bit unsigned int but have the unsigned int
> not use the sign bit for value representation? (so INT_MAX ==
> UINT_MAX == 2^32-1)

There has been some discussion about this recently, and
apparently, the wording of the C++ standard doesn't allow this.
I'm pretty sure that this was unintentional, however, as the C
standard explicitly allows it, and it is necessary on machines
with no hardware support for unsigned (Unisys MCP, for example).
There is currently an open issue concerning it before the C++
standards committee (active issue 689, open).

> - a 33bit int and a 33bit unsigned int and both types have the
> 33th bit as padding?

> By reading 3.9.1 I suppose they can have padding.

Certainly. On a Unisys MCP:
CHAR_BIT == 8
sizeof(int) == 6
INT_MAX == 2^39
UINT_MAX == 2^39
48 bits, 8 padding, 1 sign. (Note that there can even be
trapping representations. On the above, the 8 padding bits are
required to be 0, although I'm not sure what happens if they
aren't.)

--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

0 new messages