0
である私はスレッドの呼び出しでエラーが発生しました:予想される「ボイド*(*)(*空)」は、引数の型
typedef struct shape{
int height;
int width;
} rectangle;
// just to denote the rectangles where width > height
typedef rectangle wider;
wider all[3]={{5,10},{2,4},{7,9}};
としてCで定義された構造を持っていると私は高さを出力機能を持っており、幅
void funct(wider shape){
printf("height: %d, width %d", shape.height, shape.width);
}
は今、私はスレッドを作成することによって、それぞれの形状のためにこれを達成したいので、私はこの試みた:
pthread_t threads[sizeof(all)];
int count=0;
for(count=0; count <sizeof(all);++count)
{
if(pthread_create(&threads[count], NULL, funct,(wider*)all[count])!=0)
{
printf("Error in creating thread: %d",count);
break;
}
}
int i=0;
for(i=0; i<count; ++i)
{
if(pthread_join(threads[i],NULL)!=0)
printf ("Eroor joining: %d"+i);
}
しかし、このショーエラー
expected 'void * (*)(void *)' but argument is of type 'void (*)(struct rectangle)'
は私が
void funct(void *wide){
wider shape=(wider)wide;
// print same as before
}
に私の機能を変更しようとしたが、これはまだ動作しません。私は何を間違えているのですか?
'より広い形状= *(広い)ワイド;'、すべての[count] 'の代わりに'&all [count] 'を渡します。ポインタ。 – Ryan
エラーメッセージを再度読んでください。スレッド関数*の引数はポインタ*ですか?ポインタが返されますか? –
また、 'sizeof'演算子はオペランド*のサイズをバイト*で返します。 'sizeof(all)'の場合、 'sizeof(wide)* 3'バイトを返します。配列内の要素数ではありません。これは 'threads'配列のサイズに影響します。 –