By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

thread argument problem

P: 4
Hi,
When compiling, I get the following message:

" nmea.c:125: warning: cast to pointer from integer of different size "

In main():
thread_talker is declared as " pthread_t thread_talker; "
pthread_create(&thread_talker,NULL,receive_talker, (void *)portfd); (line 125)


In my .h file:
short portfd;
void *receive_talker(void* portfd);


receive_talker is written like this after main():

void *receive_talker(void *portfd) {
...
}

I don't understand what causes this warning. If anybody can help...

Thanks,
erwann
Mar 21 '07 #1
Share this Question
Share on Google+
4 Replies


DeMan
100+
P: 1,806
Me thinks you should declare portfd as a pointer to a short (or pass it's reference) eg
Expand|Select|Wrap|Line Numbers
  1. short *portfd;
  2.  
OR
Expand|Select|Wrap|Line Numbers
  1. pthread_create(&thread_talker,NULL,receive_talker,(void *)(&portfd));
  2.  
Basically the compiler does not like you casting a short to a pointer....
Mar 21 '07 #2

P: 4
I tried the second option and it is working fine

Thanks a lot



Me thinks you should declare portfd as a pointer to a short (or pass it's reference) eg
Expand|Select|Wrap|Line Numbers
  1. short *portfd;
  2.  
OR
Expand|Select|Wrap|Line Numbers
  1. pthread_create(&thread_talker,NULL,receive_talker,(void *)(&portfd));
  2.  
Basically the compiler does not like you casting a short to a pointer....
Mar 22 '07 #3

DeMan
100+
P: 1,806
Any Time!!!
Mar 22 '07 #4

P: 4
Hmm.. Actually it is not working fine. I can compile without error message but when running the program I have:

" Segmentation fault "

...and the execution stops

from a printf("portfd %d\n", (int) portfd )) I can get:

portfd = 268513978 supposed to be smth like 1 or 2...

I ve got the same 268513978 with :
printf("portfd %d\n", (int *) portfd ))

so I guess something is wrong with either the way my variable is passed to the thread or with the way I use the passed variable in my start routine.

Any iidea of what's wrong in my code?
Mar 24 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.