473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

integral (non char) types allow padding?

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

Aug 7 '08 #1
2 1667
On Thu, 07 Aug 2008 14:25:44 +0000, Mihai Rusu <di***@1and1.rowrote
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
Aug 8 '08 #2
On Aug 7, 4:25 pm, Mihai Rusu <di...@1and1.rowrote:
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:ja*********@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
Aug 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Shailesh | last post by:
One problem I've been wrestling with for a long time is how to use the C++ integral data types, vis-a-vis their size. The C++ rules guarantee that a char is at least 1 bytes, a short and int at...
14
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
43
by: ark | last post by:
Risking to invoke flames from one Tom St Denis of Ottawa :) Is there any guarantee that, say, sizeof(int) == sizeof(unsigned int) sizeof(long) > sizeof(char) ? Thanks, Ark
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
10
by: Tomás | last post by:
When you simply want to store a number, what integral type do you use? For instance, let's say we have the following in a Poker game: struct Card { enum Suit { Hearts, Diamonds, Spades, Clubs...
30
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
14
by: Thurston Manson | last post by:
Suppose I'm using an implementation where an int is 16 bits. In the program below, what function is called in the first case, and what is called in the second case? Also, if there is a difference...
13
by: Ioannis Vranos | last post by:
Is there any mentioning in the standard of the number of bits of the various built in types, apart from char/signed char/unsigned char types? Or only about the minimum value ranges of them?
2
by: Ranganath | last post by:
Hi, Why is there a restriction that only integral types can be made static constant members of a class? For e.g., class B { private: static const double K = 10; };
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.