相关疑难解决方法(0)

警告:从/向不同大小的整数转换为/从指针转换

我正在学习Pthreads.我的代码按照我想要的方式执行,我可以使用它.但它给了我一个关于编译的警告.

我编译使用:

gcc test.c -o test -pthread
Run Code Online (Sandbox Code Playgroud)

与GCC 4.8.1.我得到了警告

test.c: In function ‘main’:
test.c:39:46: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     pthread_create(&(tid[i]), &attr, runner, (void *) i);
                                              ^
test.c: In function ‘runner’:
test.c:54:22: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   int threadnumber = (int) param;
                      ^
Run Code Online (Sandbox Code Playgroud)

此错误来自以下代码:

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>

#define MAX_THREADS 10

int sum; /* this data is shared by the thread(s) */
void *runner(void * param);

int main(int argc, …
Run Code Online (Sandbox Code Playgroud)

int gcc void-pointers gcc-warning

26
推荐指数
1
解决办法
7万
查看次数

标签 统计

gcc ×1

gcc-warning ×1

int ×1

void-pointers ×1