I am looking at a C client-server program and encountered this problem. The compiler complains that the function “return with a value, in function returning void”.
My question is, what is the point of returning (NULL) as opposed to simply return? Is this perhaps to avoid the caller from getting garbage back?
void *ThreadMain(void *threadArgs)
{
int clntSock; /* Socket descriptor for client connection */
/* Guarantees that thread resources are deallocated upon return */
pthread_detach(pthread_self());
/* Extract socket file descriptor from argument */
clntSock = ((struct ThreadArgs *) threadArgs) -> clntSock;
free(threadArgs); /* Deallocate memory for argument */
HandleTCPClient(clntSock);
return (NULL);
}
You have some other function which has a return type
voidand you are returning a value from that function. But the function you posted is not that function. Basically the function you have posted has nothing to do with your problem 🙂The one you posted has a return type
void *which is different fromvoid. So this is not the function the compiler complains about. Look at other functions in your code that returnvoid(notvoid *) and you have a return in one (or more) of them.