# 指针类型之间的转换Conversions to and from Pointer Types

• 如果指针的大小大于或等于整型的大小，则指针的行为类似于转换中的无符号值，除非它无法转换为浮点值。If the size of the pointer is greater than or equal to the size of the integral type, the pointer behaves like an unsigned value in the conversion, except that it cannot be converted to a floating value.

• 如果指针小于整型，则指针首先转换为与整型大小相同的指针，然后转换为整型。If the pointer is smaller than the integral type, the pointer is first converted to a pointer with the same size as the integral type, then converted to the integral type.

相反，整型可以基于以下规则转换为指针类型：Conversely, an integral type can be converted to a pointer type according to the following rules:

• 如果整型与指针类型的大小相同，则转换只会促使整数值被视为指针（无符号整数）。If the integral type is the same size as the pointer type, the conversion simply causes the integral value to be treated as a pointer (an unsigned integer).

• 如果整型类型的大小与指针类型的大小不同，则使用表从带符号整型类型转换从无符号整型类型转换中给定的转换路径，首先将整型转换为指针的大小。If the size of the integral type is different from the size of the pointer type, the integral type is first converted to the size of the pointer, using the conversion paths given in the tables Conversion from Signed Integral Types and Conversion from Unsigned Integral Types. 然后将其视为一个指针值。It is then treated as a pointer value.

带值 0 的整型常量表达式或到类型 void * 的表达式转换可以通过类型转换、赋值或者与指向任何类型的指针进行比较来进行转换。An integral constant expression with value 0 or such an expression cast to type void \* can be converted by a type cast, by assignment, or by comparison to a pointer of any type. 这将产生与同一类型的另一个 null 指针相等的 null 指针，但此 null 指针与指向函数或对象的任何指针不相等。This produces a null pointer that is equal to another null pointer of the same type, but this null pointer is not equal to any pointer to a function or to an object. 常数 0 以外的整数可以转换为指针类型，但结果是不可移植的。Integers other than the constant 0 can be converted to pointer type, but the result is not portable.