在一些在 GCC 4.6 上编译良好的遗留代码(使用 -fpermissive
)中,我有这个:
uint16_t a = 0;
void* b = ...;
if(b == a) // ...
这种比较在 GCC 4.6 上定义明确吗?它向下转换为 16 位还是向上转换为 32/64 位?
最佳答案
看起来它向上转换了 16 位整数以匹配指针大小。
运行以下代码输出 "upcast"
uint16_t a = 1;
void* b = (void*)0x10001;
(b == a) ? printf("downcast") : printf("upcast");
关于c++ - 将 void* 与 uint16_t 进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22863470/