C99(ISO/IEC 9899:1999)中规定enum的类型为int
Ch 6.7.2.2
Constraints
2 The expression that defines the value of an enumeration constant shall be an integer constant expression that has a value representable as an int.
Semantics
3 The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted.
C++2003(ISO/IEC 14882:2003)则规定enum在“能用int表示时类型为范围不大于int的整型”,即如果int不能表示则可以使用更宽的整型。
Ch 7.2
The underlying type of an enumeration is an integral type that can represent all the enumerator values defined in the enumeration. It is implementation-defined which integral type is used as the underlying type for an enumeration except that the underlying type shall not be larger than int unless the value of an enumerator cannot fit in an int or unsigned int.
注意,unsigned int和int的宽度一样。
星期二, 四月 21, 2009
订阅:
博文评论 (Atom)
没有评论:
发表评论