小编Ais*_*nan的帖子

不兼容的指针类型将“void (void *)”传递给“void *”类型的参数

我创建了 pthread 如下:

void function1(void *s) {
start = (*(int *)s ;
}

pthread_t threads[numthreads];
int ids[numthreads];
for (i = 0; i < numthreads; i++) {
    ids[i] = i;
    int * p = &ids[i] ;
    pthread_create(&threads[i], NULL, function1, (void *)p);
}

Run Code Online (Sandbox Code Playgroud)

但这给了我错误:

>> mpicc -o hprogram hprogram.c
warning: incompatible pointer types passing 'void (void *)' to
      parameter of type 'void * _Nullable (* _Nonnull)(void * _Nullable)'
      [-Wincompatible-pointer-types]
                        pthread_create(&threads[i], NULL, function1, (void *)...
                                                          ^~~~~~~~~~
/usr/include/pthread.h:328:31: note: passing argument to parameter here …
Run Code Online (Sandbox Code Playgroud)

c pthreads

1
推荐指数
1
解决办法
1797
查看次数

标签 统计

c ×1

pthreads ×1