- 论坛徽章:
- 0
|
4 There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int. (These and other types may be designated in several additional ways, as described in 6.7.2.) There may also be implementation-defined extended signed integer types.2 The standard and extended signed integer types are collectively called signed integer types.29)
6 For each of the signed integer types, there is a corresponding (but different) unsigned integer type (designated with the keyword unsigned) that uses the same amount of storage (including sign information) and has the same alignment requirements. The type _Bool and the unsigned integer types that correspond to the standard signed integer types are the standard unsigned integer types. The unsigned integer types that correspond to the extended signed integer types are the extended unsigned integer types. The standard and extended unsigned integer types are collectively called unsigned integer types.30)
脚注:30) Therefore, any statement in this Standard about unsigned integer types also applies to the extended unsigned integer types
15 The three types char, signed char, and unsigned char are collectively called the character types. The implementation shall define char to have the same range, representation, and behavior as either signed char or unsigned char.35)
脚注:35) CHAR_MIN, defined in <limits.h>, will have one of the values 0 or SCHAR_MIN, and this can be used to distinguish the two options. Irrespective of the choice made, char is a separate type from the other two and is not compatible with either.
我英文不好,所以看这几个条件的时候,将其理解为unsigned char也是C99中明文规定的,不知道这样的理解是否正确。另外,C99中规定了unsigned char与signed char的范围:
— minimum value for an object of type signed char
SCHAR_MIN -127 // -(27 - 1)
— maximum value for an object of type signed char
SCHAR_MAX +127 // 27 - 1
— maximum value for an object of type unsigned char
UCHAR_MAX 255 // 28 - 1
所以,没有明白为什么说C99没有定义unsigned char这个是问题之一,问题之二,C99中又是何处说了需要编译器自己选择char是unsigned还是signed,对于两个表示范围差剧如此之大的类型,选择的依据是什么?
对于嵌入式平台,unsigned确实优于signed,因此编译选项可以配置char默认为unsigned,但这个并不足以说明是编译器能够自己去选择。 |
|