[問題] pthread編譯過不了

看板C_and_CPP (C/C++)作者 (QQ)時間13年前 (2012/10/25 17:14), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) G++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) pthread.h 問題(Question): 編譯過不了 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <pthread.h> void thread(){ int i; for(i=0;i<3;i++) printf("This is a pthread.\n"); } int main(){ pthread_t id; int i,ret; pthread_create(&id,NULL,(void *) thread,NULL); for(i=0;i<3;i++) printf("This is the main process.\n"); pthread_join(id,NULL); return 0; } 補充說明(Supplement): 這支是網路上找的範例程式 執行結果應該會生出一條thread和main搶著印出訊息3次 不過在編譯的時候卻過不了 想請問是什麼問題? 小弟功力薄弱實在看不懂0rz 有請各位解答 謝謝 編譯訊息如下: now.cpp:15:46: error: invalid conversion from 'void*' to 'void* (*)(void*)' [-fpermissive] /usr/include/pthread.h:225:12: error: initializing argument 3 of 'int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)' [-fpermissive] -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.109.16.164

10/25 17:28, , 1F

10/25 17:30, , 2F
thread 的函式必須是 void *thread(void *arg) 的格式
10/25 17:30, 2F

10/25 17:37, , 3F
問題解決 感謝樓上^^
10/25 17:37, 3F
文章代碼(AID): #1GYGBwxo (C_and_CPP)
文章代碼(AID): #1GYGBwxo (C_and_CPP)