Gewusst wie: Umwandlung einer Ganzzahl in void-pointer?

Beim arbeiten mit Threads in C, ich bin vor der Warnung

"warning: cast to pointer from integer of different size"

Den code wie folgt

#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
#include<pthread.h>
void *print(void *id)
{
 int a=10;
 printf("My thread id is %ld\n",pthread_self());
 printf("Thread %d is executing\n",id);
 return (void *) 42;
}

int main()
{
 pthread_t th[5];
 int t;
 int i;
 int status;
 void *ret;
 for(i=0;i<5;i++)
 {
   status=pthread_create(&th[i],NULL,print,(void *)i); //Getting warning at this line
   if(status)
   {
    printf("Error creating threads\n");
    exit(0);
   }
   pthread_join(th[i],&ret);
   printf("--->%d\n",(int *)ret);
 }
 pthread_exit(NULL);
}

Kann jemand erklären, wie die übergabe eines integer in eine Funktion erhält (void * ) als parameter?

InformationsquelleAutor der Frage Dinesh | 2011-12-13

Schreibe einen Kommentar