警告warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

一般:
void *tfn(void *arg)
{
int i;
i = (int)arg;
sleep(i); //通过i来区别每个线程
printf(“I’m %dth thread, Thread_ID = %lu\n”, i+1, pthread_self());
return NULL;
}
。。。
int main(int argc, char *argv[])
{
for (i = 0; i < n; i++) {
pthread_create(&tid, NULL, tfn, (void *) i);
//将i转换为指针,在tfn中再强转回整形。
}
}

在编译时,由于字节数不一样,可能会出现类型转换的警告。

当使用下面时就不会了
i = (intptr_t)arg;

pthread_create(&tid, NULL, tfn, (void *)(intptr_t)i);

警告warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]一般:void *tfn(void *arg){int i;i = (int)arg;sleep(i); //通过i来区别每个线程printf(“I’m %dth thread, Thread_ID = %lu\n”, i+1, pthread_self());return NULL;}。。。int main(int arg
在多线程编程中使用 thread_start(pthread_t * thread_id, THREAD_BODY * thread_workbody, void *thread_arg);  创建子线程时因为最后一个参数需要是指向子线程的文件描述符(int类型)的指针,因此调用时我们会将文件描述符强转为(void *)类型,可能是系统不同的原因在int类型强转为void类型指针会出现: 参考原文:https://blog.csdn.net/qq_17308321/article/details/79979514 警告 :不是错误的,但是有风险或表明可能有错误。 英文原文:http://gcc.gnu.org/onlinedocs/gcc-4.6.3/gcc/Warnin...
解决 warning : cas t to point er from integer of diff erent size [- Win t-to- point er - cas t]
今天做线程的例程出现 warning : cas t to point er from integer of diff erent size [- Win t-to- point er - cas t]的 警告 编译结果: 0 在网站https://stackov er flow.com/questions/9251102/ warning - cas t-to- point er -from- integer -of- diff er e...
解释一下和这个报错 warning : cas t to point er from integer of diff erent size [- Win t-to- point er - cas t]
将int变量转为(void*)时出现错误 er ror: cas t to point er from integer of diff erent size [-W er ror=int-to- point er - cas t] 这是由于int类型为32位,指针为long long 64位 解决方法:(void*)(intptr_t)...
今天在编写多线程程序的时候,编译过程中出现了如下错误: thread.c: In function ‘main’: thread.c:38:57: warning : cas t to point er from integer of diff erent size [- Win t-to- point er - cas t] 后来google了,受这个问题解决的启发http://stackov er flow.
警告 warning : cas t from point er to integer of diff erent size [-W point er -to-int- cas t] int *ret[5]; printf("-------%d 's ret = %d\n", i, (int)ret[i]); 出现类型转换 警告 printf("-------%d 's ret = %ld\n", i,(intptr_t )(int *)ret[i]); 警告warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] 南征北战zZZ: 你这转换的变量类型也没说明呀= = 警告warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] ctotalk: thanks very good strcpy,memcpy区别与实现 ctotalk: very good