T
thinking
Grünschnabel
in my prog i'm using threads
so i use pthread_create function to start them
one argument for my thread is e.g. an int value
example:
int somevar = 10;
pthread_create(&threadstruct,NULL,threadfunc,(void*)somevar);
this worked on my 32bit test environment perfectly and for the 64bit stuff it works too, but i get a warning
the first warning is: warning: cast to pointer from integer of different size
i understand why i get this, but i'm not sure, how i can solve the problem
well, on 64bit int is 4byte and void* is 8byte in size (i tested it with sizeof())
so i tried casting like this: (void*)(long*)somevar but i got the same warning
Q1: any hint wo i can remove the warning, with good valid code
i don't want to ignore such stuff
a possible solution could be something like this:
i got a similar problem on the "other" side of the thread
using the code above i got this warning: warning: cast from pointer to integer of different size
the solution was:
EDIT:
hoppala: natürlich hat es so funktioniert: pthread_create(&threadstruct,NULL,threadfunc,(void*)(long)somevar);
so i use pthread_create function to start them
one argument for my thread is e.g. an int value
example:
int somevar = 10;
pthread_create(&threadstruct,NULL,threadfunc,(void*)somevar);
this worked on my 32bit test environment perfectly and for the 64bit stuff it works too, but i get a warning
the first warning is: warning: cast to pointer from integer of different size
i understand why i get this, but i'm not sure, how i can solve the problem
well, on 64bit int is 4byte and void* is 8byte in size (i tested it with sizeof())
so i tried casting like this: (void*)(long*)somevar but i got the same warning
Q1: any hint wo i can remove the warning, with good valid code
i don't want to ignore such stuff
a possible solution could be something like this:
i got a similar problem on the "other" side of the thread
Code:
static void* class::threadfunc(void *arg){
int somevar = (int)arg;
}
the solution was:
Code:
int somevar = (int)(long)arg;
EDIT:
hoppala: natürlich hat es so funktioniert: pthread_create(&threadstruct,NULL,threadfunc,(void*)(long)somevar);
Zuletzt bearbeitet: