(void *) (void*) (product) what is it?
(void *) (void*) (product) what is it?
It looks like a cast of product to void*, then another unnecessary cast to void* again.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Yeah, that's it. Remove one of the two (void*) as it has no net effect.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
pthread_create() seems to take a function pointer to a void* func(void*) type of function. I might be wrong though, the function pointer syntax in C is quite confusing.
Then product should have been defined as such a function; no casting needed. If you do want to cast, use a typedef: but then there's the issue of undefined behaviour if you're not careful.
EDIT:
I can't say I have much experience with casting to function pointer types, and in fact I usually typedef when I do have to deal with function pointers at all, but a quick check shows that if indeed the intention was to cast product to such a function pointer type without benefit of a typedef, it should have been: (void*(*)(void*))product
EDIT #2:
Well, another quick check shows that pthread_create looks like this:
So, cronus, while you're right that pthread_create does take such a function pointer, in alex01's post #3 that would be dotProduct, not the expression in question.Code:int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
Last edited by laserlight; 05-15-2020 at 05:23 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Oh right, hadn't noticed that that weird cast was for just the normal void* argument. Indeed in that case, the second (void*) makes no sense.