Quote:
Originally Posted by
prompt
The code at the first post is complete! Is only a test!
The version of gcc is 4.2.1 and I'm on Mac OSX!
Well, I thought maybe your warnings were all from not using #include if it's not there - but they'd probably be errors. Also, posting the complete source (including #include directives) means that the warning messages you print will mean something - if your code were complete, you'd have errors at the definition of main() and your return statement that just don't match up - luckily it's quite simple code, and working out where the errors "really" are isn't much of a problem.
Trust me, cutting and pasting the complete source when you post error messages helps.
Either way, missing includes is obviously not your problem.
Your first problem is several problems. In "pthread_exit((void *)y)", you're telling pthread_exit there's a return value at address 10 - I'm surprised it doesn't segfault*. You want the result to be stored at the address of y, so it should be "pthread_exit(&y)".
Your second problem is also the culmination of two problems - instead of declaring "ret" to be a "void *", you may as well be more type-safe and declare it an "int *", and then "int nm = (int*)ret;" should become "int nm = *ret;".
As a third point - I hope you can see that the number of things wrong in such a short piece of code should ring some alarm bells. You don't seem to have fully grasped the concepts of pointers or types. You should
definitely find a tutorial on pointers and have a good study of it - go through all the exercises, make sure you understand
all of it. They're very important, and can lead to subtle and hard-to-detect bugs (as well as your programs haemorrhaging segfaults) if misused. This code may work, but that's only because you misuse your pointers one way, then manage to misuse them in exactly the opposite way.
* Mind you, the different sizes problem is weird - are you programming for an embedded device or something?
P.S. Oh, but then y is on the stack in th(). You probably don't want that - make it static or put it outside the function definition (or malloc() it), but make sure it's not on the stack.