void vs void * when declaring function

As i know void is being used when declaring a function with no return type. But i came across some function declarations stating with void * .
eg:-

void *do_this()

According to my knowledge do_this can be treated as a function which returns a void pointer. but when i went though some of the codes with above function declaration i realized that it does not return any pointer as the return value. So im confused with this usage... can some one give a better explanation for this?

Thanx in advance
Last edited on
Your understanding is correct. void* do_this(); returns a void pointer.

The function must have been returning something. Perhaps you were misreading the function? Can you post a code snippit of the function in question?
Thanks for the quick response. Actually im dealing with some threading examples using pthread library. here is the code snippet

void * do_work(void * t){

int i;
long tid;
double result =0.0;
tid = *(long*)t;
cout << " Thread " << tid << "starting" << endl;
if (tid == 2){
sleep(15);
}
cout << " Thread " << tid << "finished" << endl;
pthread_exit(NULL);

}

As u explained here pthread_exit() might be returning a void * . but if i see the decraraion of it its is also defined as void as follows.

extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));

So I cant find out any return in do_work function.



The code is wrong, in this case. If you try compiling it, the compiler should be giving you an error (or at least a warning).

The function should be returning something.
Topic archived. No new replies allowed.