私はpthreadの例を試しています。ここに私のコードです:エラー:タイプ 'int'の変数を型 'void'の左辺値で初期化できません
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
void*AsalK1(void *gelen);
int main(){
int *i;
i= new int;
*i=1;
int sonSayi;
pthread_t th1, th2, th3, th4;
printf("---------------------------------------------\n");
printf("| Threadler ile Asal Sayi Bulma |\n");
printf("---------------------------------------------\n");
printf("Son sayi degeri: 1000000 \n");
int r1=pthread_create(&th1, NULL, AsalK1, (void *)i);
*i=3;
int r2=pthread_create(&th2, NULL, AsalK1, (void *)i);
*i=5;
int r3=pthread_create(&th3, NULL, AsalK1, (void *)i);
*i=7;
int r4=pthread_create(&th4, NULL, AsalK1, (void *)i);
pthread_join(th1, NULL);
pthread_join(th2, NULL);
pthread_join(th3, NULL);
pthread_join(th4, NULL);
return 0;
}
void *AsalK1(void *gelen){
int bas= *gelen;
printf("bas :&d\n",bas);
}
と私はコンパイルするために、このコードを使用します。
gcc -lpthread ThreadDeneme.cpp
または
g++ -lpthread ThreadDeneme.cpp
とエラーが言う:
は、変数を初期化することはできません型 'int'の左辺値が の場合 'void' int b as = * gelen;私はこの使用
:
int型BAS =(int型*)gelenを。
しかし、まだ進行中です。
私が読んで:エラーメッセージに関連する問題に対処する
What is the difference between these uses of pointers?
コードを編集してインデントを修正してください。また、C++タグを削除します。私はこの質問を読まない。 – Lundin
@Lundinとは対照的に、 'i = new int;'はCではありません。正しくタグ付けし、言語を混ぜてはいけません。 – unwind
@unwind同様に、最初の '#include'はC++ではありません。 –
Lundin