C语言标准说int型至少和short一样大. 也就是说至少16bit, 具体实现要看编译器. 类似的还有long int型, 标准说至少32位, 可能是64位, 也可能是40位(CCS5.2 C6000的7.3版编译器). 还有 long long 型, 既可以是64位, 也可能是40位(CCS5.2 的4.4版C5500 编译器就是). 所以, 使用一款编译器首先就要看编译器手册. 当然有的编译器是不严格遵守C标准的. Keil C51就是一个.
这里摘抄一段C99标准"6.3.1.1 Boolean, characters, and integers"节话共同学习, 英语不好就不翻译了:
"Every integer type has an integer conversion rank defined as follows:— No two signed integer types shall have the same rank, even if they hav e the same representation.
— The rank of a signed integer type shall be greater than the rank of any signed integer
type with less precision.
— The rank of long long int shall be greater than the rank of long int, which
shall be greater than the rank of int, which shall be greater than the rank of short
int, which shall be greater than the rank of signed char.
— The rank of any unsigned integer type shall equal the rank of the corresponding
signed integer type, if any.
— The rank of any standard integer type shall be greater than the rank of any extended
integer type with the same width.
— The rank of char shall equal the rank of signed char and unsigned char.
— The rank of _Bool shall be less than the rank of all other standard integer types.
— The rank of any enumerated type shall equal the rank of the compatible integer type
(see 6.7.2.2).
— The rank of any extended signed integer type relative to another extended signed
integer type with the same precision is implementation-defined, but still subject to the
other rules for determining the integer conversion rank.
— For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has
greater rank than T3, then T1 has greater rank than T3.
"
[attach]111595[/attach]
[ 本帖最后由 KISSMonX 于 2013-2-21 09:43 编辑 ]
详情回复
发表于 2013-2-21 17:28
这里摘抄一段C99标准"6.3.1.1 Boolean, characters, and integers"节话共同学习, 英语不好就不翻译了:
"Every integer type has an integer conversion rank defined as follows:— No two signed integer types shall have the same rank, even if they hav e the same representation.
— The rank of a signed integer type shall be greater than the rank of any signed integer
type with less precision.
— The rank of long long int shall be greater than the rank of long int, which
shall be greater than the rank of int, which shall be greater than the rank of short
int, which shall be greater than the rank of signed char.
— The rank of any unsigned integer type shall equal the rank of the corresponding
signed integer type, if any.
— The rank of any standard integer type shall be greater than the rank of any extended
integer type with the same width.
— The rank of char shall equal the rank of signed char and unsigned char.
— The rank of _Bool shall be less than the rank of all other standard integer types.
— The rank of any enumerated type shall equal the rank of the compatible integer type
(see 6.7.2.2).
— The rank of any extended signed integer type relative to another extended signed
integer type with the same precision is implementation-defined, but still subject to the
other rules for determining the integer conversion rank.
— For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has
greater rank than T3, then T1 has greater rank than T3.
" C99-ISO.pdf(1.35 MB, 下载次数: 9)