integral (non char) types allow padding?

M

Mihai Rusu

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.
 
J

James Kanze

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top