Hi there. I've just written an extremely simple cross-platform wrapper for posix threads. I compiled it on unix and it compiles with no errors. The windows side with MinGW... not so pretty.

gcc compiles fine but throws a couple of warnings at me (I'll explain in a bit.) g++ gives me errors.

I'm compiling with '-Wall -ansi -g' switches.

The error that I'm getting is related to the _beginthreadex function. In my header file I've defined this:


  1. #ifdef _WIN32
  2. #define THREAD_PROC unsigned (*)(void*)
  3. #else
  4. #define THREAD_PROC void* (*)(void*)
  5. #endif
  6.  
  7. THREAD_T InitiateDetachedThread(THREAD_PROC, void*);

And in my .c file is:


  1. #ifdef _WIN32
  2. THREAD_T InitiateDetachedThread(unsigned (*start)(void*), void* a) {
  3. return (THREAD_T)_beginthreadex(NULL, 0, start, a, 0, NULL);
  4. }
  5. #else
  6. THREAD_T InitiateDetachedThread(void* (*start)(void*), void* a) {
  7. THREAD_T t;
  8. pthread_create(&t, NULL, start, a);
  9. pthread_detach(t);
  10. return t;
  11. }
  12. #endif /*_WIN32*/


Like I said, the unix side compiles with no complaints. When i compile with gcc on MinGW I get:


$ gcc -Wall -ansi -g -c threads.c
threads.c: In function `InitiateDetachedThread':
threads.c:16: warning: passing arg 3 of `_beginthreadex' from incompatible pointer type


And g++ gives me the full-blown error:

threads.c: In function `void* InitiateDetachedThread(unsigned int (*)(void*), void*)':
threads.c:16: error: invalid conversion from `unsigned int (*)(void*)' to `unsigned int (*)(void*)'
threads.c:16: error: initializing argument 3 of `long unsigned int _beginthreadex(void*, unsigned int, unsigned int (*)(void*), void*, unsigned int, unsigned int*)'


I don't get why it won't cast... it shouldn't have to! It's like the compiler's saying "Can't cast from int to int."

Click Here View photos of singles in your area