我想打印空指针的地址
u32 j;
for (j = 0; j < sizeof(struct queue_header); j += 4)
{
printf("0x%x ",(u32 *)((u32 *)q->q_hdr + j)); //q_hdr is a void pointer
}
但是这种类型转换给出了错误:
warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
你能告诉我如何打印地址吗?
最佳答案
这就是 %p
的用途:打印指针。
printf("%p ", (void *)((u32 *)q->q_hdr + j));
应该做你想做的。
关于c - 空指针类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27502231/