power_output
power_output

Reputation: 421

machine's basic character set

In C++ primer book, in the primitive built-in types section is says:

A char is guaranteed to be big enough to hold numeric values corresponding to the characters in the machine's basic character set. That is, a char is the same size as a single machine byte.

Is this basic character refering to the ASCII table?

Upvotes: 2

Views: 1180

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 148890

The standard does not guarantee that the basic character set shall be ASCII. And in fact other character sets have existed and still exist on specific systems such as EBCDIC.

The only guarantees are

1.7 The C++ memory model [intro.memory]
1 The fundamental storage unit in the C++ memory model is the byte. A byte is at least large enough to contain any member of the basic execution character set (2.3) and the eight-bit code units of the Unicode UTF-8 encoding form and is composed of a contiguous sequence of bits, the number of which is implementationdefined. The least significant bit is called the low-order bit; the most significant bit is called the high-order bit. The memory available to a C++ program consists of one or more sequences of contiguous bytes. Every byte has a unique address.

1.8 The C++ object model [intro.object]
...
5 Unless it is a bit-field (9.6), a most derived object shall have a non-zero size and shall occupy one or more bytes of storage.

2.3 Character sets [lex.charset]
...the value of each character after 0 in the above list of decimal digits shall be one greater than the value of the previous.

So the C++ standard guarantees that a char has at least 8 bits and that the digit codes have consecutive values. All other character set properties are implementation dependant.

Upvotes: 2

Related Questions