2014-03-27 69 views
-3

不知道爲什麼,但是......什麼會導致錯誤簡單的解釋

的main.c:126:4:錯誤:無法轉換爲指針類型的main.c:126 :4:警告:從不兼容指針類型[默認啓用]傳遞'pthread_create'的參數3 /usr/include/pthread.h:225:12:note:expected'void *(*)(void )'但參數的類型是'void()(struct arrayslice)'

我已經正確原型化了這個函數,據我所知。

struct People{ 

    int count; 
    int levels; 
}; 



struct arrayslice *args = &current; 
pthread_create(&thread, NULL, countall, (void*) &args); 
+0

這裏的東西是不正確的,你是不是給我們足夠的信息。 「pthread_create」的原型是什麼樣的?你正在向它傳遞錯誤的觀點。 我懷疑你傳遞了一個雙指針,當你應該傳遞一個指針時。 – RandomGuy

+0

第三個參數是'countall',但你沒有包括它的聲明,那麼你怎麼能指望任何人回答你的問題? –

+0

來吧,@RandomGuy,您可以在手冊頁上找到pthread_create的原型,並且此錯誤消息還提供了預期的類型。 –

回答

1

您可以參考下面的文章。這個包含有關pthread的有用信息以及相關示例和解釋。

https://computing.llnl.gov/tutorials/pthreads/

expected ‘void * (*)(void)’ but argument is of type ‘void()(struct arrayslice)’

那麼關於你的編譯錯誤,那是因爲你沒有傳遞正確的函數指針在第三個參數。它看起來像你的功能是

void countall(struct arrayslice); 

然而並行線程期待你的函數應該是

void* countall(void* arrayslice); 
+1

謝謝...新的和我在Stack上搜索了一堆其他帖子,像http://stackoverflow.com/questions/21417832/cant-create-thread-properly?rq=1和http://stackoverflow.com/questions/20196121/passing-struct-並且很難找出答案。我現在明白了。 – user2499298