C++ Logo

sg12

Advanced search

Re: [ub] [c++std-ext-14555] Sized integer types and char bits

From: Ion Gaztañaga <igaztanaga_at_[hidden]>
Date: Sat, 19 Oct 2013 08:37:03 +0200
El 19/10/2013 5:19, Lawrence Crowl escribió:
> On 10/18/13, John Spicer <jhs_at_[hidden]> wrote:
>> What does requiring CHAR_BIT == 8 buy us? Sorry if I missed that
>> detail in the large volume of messages in this thread.
>
> Since the introduction of UTF-8 literals, we have required CHAR_BIT
>> = 8. So, the change would be to cap CHAR_BIT at 8. I remember
> something about a 24-bit system on the gcc mailing lists a couple of
> years ago, but I don't remember what happened with char.

[Sorry, I sent a previous reply to the UB list with the wrong subject]

CHAR_BIT is at least 8, which is enough to hold UTF-8 literals. And
"16/32 bit" character typedefs (in uchar.h for C++) or fundamental types
(in C++11) are a bit confusing, as char16_t/char32_t don't follow
stdint.h naming conventions. Following stdint.h guidelines they would
have been named char_least16_t/char_least32_t because they don't
guarantee exactly 16/32 bits. I know some coding standards that extend
stdint.h typedefs for character types that try to hide this issue for
programmers:

//Mandatory character types
typedef char acme_char_least8_t;
typedef char16_t/uint_least16_t acme_char_least16_t;
typedef char32_t/uint_least16_t acme_char_least32_t;

//Optional character types

//If CHAR_BIT is 8
typedef char acme_char8_t;

//If sizeof(acme_char16_t)*CHAR_BIT is 16
typedef char16_t/uint_least16_t acme_char16_t;

//If sizeof(acme_char32_t)*CHAR_BIT is 32
typedef char32_t/uint_least16_t acme_char32_t;


For modern systems with CHAR_BIT != 8, please see:

----------------------
24-bit Freescale DSPs:
http://www.freescale.com/webapp/sps/site/homepage.jsp?code=563XXGPDSP
----------------------

 From the C compiler(http://application-notes.digchip.com/314/314-68461.pdf)

"Data Type / Size (words) / Min value / Max value

char / 1 / -8388608 / 8388607
unsigned char / 1 / 0 / 0xFFFFFF
short / 1 / -8388608 / 8388607
unsigned short / 1 / 0 / 0xFFFFFF
int / 1 / -8388608 / 8388607
unsigned int / 1 / 0 / 0xFFFFFF
long / 2 / -140737488355328 / 140737488355327
unsigned long / 2 / 0 / 0xFFFFFFFFFFFF"

----------------------
Analog Devices 32 bit DSPs:
http://www.analog.com/en/processors-dsp/tigersharc/products/index.html
----------------------

 From the C compiler
(http://www.analog.com/static/imported-files/software_manuals/50_ts_cc_man.4.1.pdf)

Type / Word Size (Bits) / Result of sizeof operator

char, signed char,unsigned char / 32 / 1
short, unsigned short / 32 / 1
int, unsigned int / 32 / 1
long, unsigned long / 32 / 1
pointer / 32 / 1

Best,

Ion

Received on 2013-10-19 08:37:26