C 标准规定 %p 应用于 void * 类型,因此正确的做法是将指针显式转换为 void *。尽管在大多数平台和编译器上省略转换也能正常工作,但这属于未定义行为,且可能触发编译器警告。为了代码的可移植性和规范性,应始终进行类型转换。
下面是标准中的描述:
Matches an implementation-defined set of sequences, which should be the same as the set of sequences that may be produced by the %p conversion of the fprintf function. The corresponding argument shall be a pointer to a pointer to void. The input item is converted to a pointer value in an implementation-defined manner. If the input item is a value converted earlier during the same program execution, the pointer that results shall compare equal to that value; otherwise the behavior of the %p conversion is undefined.
下面是标准中的描述:
Matches an implementation-defined set of sequences, which should be the same as the set of sequences that may be produced by the %p conversion of the fprintf function. The corresponding argument shall be a pointer to a pointer to void. The input item is converted to a pointer value in an implementation-defined manner. If the input item is a value converted earlier during the same program execution, the pointer that results shall compare equal to that value; otherwise the behavior of the %p conversion is undefined.


草酱
香菜味包子
XeO2