Bitwise Operator Effects on Padding Bits

T

Tim Rentsch

Ben Bacarisse said:
Keith Thompson said:
Ben Bacarisse said:
Keith Thompson <[email protected]> writes: [...]
It's not clear (to me, anyway) what the width of _Bool is supposed to
be. It seems to me that the Standard doesn't preclude either of the
following (assume CHAR_BIT==8 and sizeof(_Bool)==1):

_Bool has 1 value bit and 7 padding bits and can only represent
the values 0 and 1; its width is 1.

_Bool has 8 value bits and can represent values from 0 to
255 inclusive (but storing a value other than 0 or 1 requires
tricks); its width is 8.

I think both are permitted along with all points in between (i.e. any
width from 1 to CHAR_BIT seems to me to be permitted). I can't find any
text that imposes any tighter constraints on the implementation.

Are widths exceeding CHAR_BIT forbidden? I know that _Bool is required
to have a lower rank than any other standard integer type, but I don't
think that implies it can't have a wider range than unsigned char
(though it could cause some interesting effects if it does).

I think you are right, and I'd come to the same conclusion while writing
another post but forgot it by the time I replied here! I see no reason
why _Bool can't be wider that unsigned char.

6.2.5p8. _Bool is an unsigned type, so its width can't
be larger than the width of unsigned char. (The range of
values determines the width, per 6.2.6.2p1 and 6.2.6.2p6.)
 
B

Ben Bacarisse

Tim Rentsch said:
Ben Bacarisse said:
Keith Thompson said:
It's not clear (to me, anyway) what the width of _Bool is supposed to
be. It seems to me that the Standard doesn't preclude either of the
following (assume CHAR_BIT==8 and sizeof(_Bool)==1):

_Bool has 1 value bit and 7 padding bits and can only represent
the values 0 and 1; its width is 1.

_Bool has 8 value bits and can represent values from 0 to
255 inclusive (but storing a value other than 0 or 1 requires
tricks); its width is 8.

I think both are permitted along with all points in between (i.e. any
width from 1 to CHAR_BIT seems to me to be permitted). I can't find any
text that imposes any tighter constraints on the implementation.

Are widths exceeding CHAR_BIT forbidden? I know that _Bool is required
to have a lower rank than any other standard integer type, but I don't
think that implies it can't have a wider range than unsigned char
(though it could cause some interesting effects if it does).

I think you are right, and I'd come to the same conclusion while writing
another post but forgot it by the time I replied here! I see no reason
why _Bool can't be wider that unsigned char.

6.2.5p8. _Bool is an unsigned type, so its width can't
be larger than the width of unsigned char. (The range of
values determines the width, per 6.2.6.2p1 and 6.2.6.2p6.)

Ah, so it is. In the context of the thread, if one encounters a system
with sizeof(_Bool) > 1 then one knows it has padding bits.
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top