您好,我試圖創建一個線程調用一個函數,它需要一個結構。 問題現在面臨的是GCC告訴我一個不兼容的指針創建線程不兼容的類型
這是錯誤
warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void * (*)(struct sonicPins *)
」
的代碼與此錯誤 pthread_create(&thr1, NULL, &threadFunc,(void*) &args1)
線;
下面是函數其試圖調用
void* threadFunc(struct sonicPins *args)
的結構也是在sonicThread.h定義的struct
以上主要功能的要點我有
struct sonicPins *args1;
在我主我
args1 = malloc(sizeof(struct sonicPins));
args1->trig1 = 21;
args1->echo1 = 20;
//front right.
args1->trig2 = 16;
args1->echo2 = 12;
//rear left;
args1->trig3 = 26;
args1->echo3 = 19;
//rear right.
args1->trig4 = 13;
args1->echo4 = 6;
我嘗試過各種方法來解決這個問題,但找不到解決問題的方法。
我回滾您的編輯,因爲它由以下毫無意義的答案。獲得答案後請不要更改代碼。發佈新問題或添加更新後的代碼而不刪除舊代碼。 –