need solution for g++ warning on 64bit

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
Code:
static void* class::threadfunc(void *arg){
 int somevar = (int)arg;
}
using the code above i got this warning: warning: cast from pointer to integer of different size
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:

Ähnliche Themen

Nginx als Reverse Proxy für Nextcloud und Emby

Email via script via Exchange Server (SASL)

Samba 4 Gast Zugang unter Ubuntu funktioniert nicht

JBidWatcher: Problem bei loading Auctions in Verbindung mit mySQL

Akonadi startet nicht mehr

Zurück
Oben