In the C++11 standard, why leave the char type implementation dependent?

isakbob

Background

Several C++ source materials and stack overflow questions talk about the implementation dependent nature of char. That is, char in C++ may be defined as either an unsigned char or a signed char, but this implementation depends entirely on the compiler according to the ARM Linux FAQ:

The above code is actually buggy in that it assumes that the type "char" is equivalent to "signed char". The C standards do say that "char" may either be a "signed char" or "unsigned char" and it is up to the compilers implementation or the platform which is followed.

This leaves the door open for both ambiguity issues and bad practices including mistaking the signage of a char when used as an 8-bit number. The Rationale for C offers some reason for why this is the case, but does not address the issue of leaving open the possibility for ambiguity:

Three types of char are specified: signed, plain, and unsigned. A plain char may be represented as either signed or unsigned, depending upon the implementation, as in prior practice. The type signed char was introduced to make available a one-byte signed integer type on those systems which implement plain char as unsigned. For reasons of symmetry, the keyword signed is allowed as part of the type name of other integral types.

It would seem advantageous to close the door to even the potential of ambiguity to leave only the types of unsigned char and signed char as the two data types for the 8-bit unit. This prompted me to ask the question...

Question

Given the potential for ambiguity, why leave the char data type implementation dependent?

isakbob

Some processors prefer signed char, and others prefer unsigned char. For example, POWER can load an 8-bit value from memory with zero extension, but not sign extension. But SuperH-3 can load an 8-bit value from memory with sign extension but not zero extension. C++ derives from C, and C leaves many details of the language implementation-defined so that each implementation can be tailored to be most efficient for its target environment.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why is initialization of a constant dependent type in a template parameter list disallowed by the standard?

Implementation dependent-type

Is a c++11 variadic function template overload with a dependent type ambiguous?

An std::move function of C++ standard 11 implementation in C

ISO C++ Standard - rules regarding examining dependent base. Why?

Why does the C++ standard specify that unqualified names in a template are non-dependent?

Why sizeof built in types except char is compiler dependent in C & C++?

C++11 type deduction vs const char *

C++11 introduced exception constructors taking `const char*`. But why?

Why is the range of signed char -127 to 127 in C++11?

Why is C platform-dependent?

Why is the type char?

Dependent non-type parameter packs: what does the standard say?

Why isn't dependent type inffered by the compiler?

Why don't I need to specify "typename" before a dependent type in C++20?

Why is the type of boost::hana::tuple_c implementation-defined?

Type-variable-dependent default method implementation in Haskell

why is 00000000 - 00000001 = 11111111 in C unsigned char data type?

Why is array of characters(char type) working with unicode characters (c++)?

Why the C++ compiler recognize the string type as char[]

Why do function composition and application have a dependent implementation in Agda?

C11 Standard docs

Why do we have the type of char in C, if a character literal is always of type int? Isn´t the whole type of char in C redundant?

Why don't Standard C Libraries need to be divided into a header and implementation file?

Why (char) + (char) = (int) in C?

How does C++ deal with NAN? Is there a standard way or is compiler dependent?

Dependent types in c++, a non zero type

C++11 why the type of 'decltype(x)' and 'decltype((x))' are different?

Narrowing conversion from 'long' to signed type 'char' is implementation-defined (strtol function in C)