int 与 void* 类型转换报错; long 与void*类型转换成功。

#include <stdio.h>

int main(int argc, char *argv[]) {
void *p = NULL;
//int test = 100;
//int idx2int = reinterpret_cast<int>(p); //error
//int idx2int = (int)p; //error
//int idx2int = static_cast<int>(p); //error
long test = 100;
p = (void*)test;
printf("\n sizeof(long)=%ld\n", sizeof(long));
printf("%ld\n", (long)p);
}

posted on 2024-01-16 09:35  huangguanyuan  阅读(67)  评论(0编辑  收藏  举报

导航