Reputation: 195
I get this error: assignment makes pointer from integer without a cast. I am using threads.
This is what I am doing:
void *calculate(void *arg) {
unsigned long *array;
.....
return array;
}
int main() {
unsigned long *result;
void *ptr;
...
p_thread_create(...);
p_thread_join(td, &ptr);
...
result = *((unsigned long *) ptr); /* This is the line where my error occurs */
return 0;
}
The calculate function returns an array of unsigned long type. The return value of the thread is stored in a void pointer and because it is void I cast it to * unsigned long.
But it's not working.
Any ideas?
Upvotes: 1
Views: 122
Reputation: 539795
If you want to return a single number (to which ptr
points) from the thread function, use
unsigned long result = *((unsigned long *) ptr);
If you want to return a pointer to an array of unsigned long
, use
unsigned long *result = ptr;
Upvotes: 3