9

I'm writing a threading program, and the pthread_create method requires a void* function.

I'm getting the "control reaches end of non-void function" warning, and I understand why (because I don't have any official return statement)- my question is really just what should I return in this case?

Is it alright to just return NULL? I don't think my return value will affect anything else in my program, but I am just wondering what the standard is for avoiding this warning when programming with multithreaded programs.

user3475234
  • 1,503
  • 3
  • 22
  • 40

2 Answers2

9

Returning NULL is fine, and is the normal way. Nothing will use the return value unless you write code to use it. NULL is a valid value for void *, and if you don't care what that value is, then the only thing that matters is that it's a valid one.

Crowman
  • 25,242
  • 5
  • 48
  • 56
4

try something like this:

#include <pthread.h>

void* you_func( void* param ) {
   // do stuff here ...
   // and terminates as follows:
   pthread_exit( NULL );
}

hope that helps you.

Zhi Q.
  • 71
  • 3
  • I noticed that using the win32 and win64 cross compilers, i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc - this compiler warning persists even with the call to pthread_exit(NULL). I didn't get the warning for gcc under native linux or the arm cross compiler (arm-linux-gnueabihf-gcc-4.8) – bph Jul 11 '17 at 15:16