In C Programming, char, signed char, and unsigned char are considered distinct data types. This behavior is different from integers, where int and signed int are the same type, and unsigned int is another separate type.
Question:
Why is it that the code below compiles differently for char than for int types?
cout << getIsTrue< isX<int8>::ikIsX >() << endl; cout << getIsTrue< isX<uint8>::ikIsX >() << endl; cout << getIsTrue< isX<char>::ikIsX >() << endl;
Answer:
C distinguishes between char, signed char, and unsigned char as three separate types. This is why the template instantiations for char, int8, and uint8 are distinct.
For integers, however, int and signed int are the same type, while unsigned int is a different type. This is why the template instantiations for int, int32, and uint32 result in only two unique templates.
The standard [basic.fundamental](https://eel.is/c draft/basic.fundamental) states:
"Plain char, signed char, and unsigned char are three distinct types."
This means that they have different object representations and can have different value ranges, depending on the implementation.
The above is the detailed content of Why are `char`, `signed char`, and `unsigned char` Treated Differently from `int`, `signed int`, and `unsigned int` in C ?. For more information, please follow other related articles on the PHP Chinese website!