strange compilation error on <stdlib.h>

Hello all,

I am trying to compile a thread program using g++ running on windows 7. I have the latest pthread lib and the compiler installed.

Here's my simple program

#include <iostream.h>
#include <pthread.h>
#include <stdlib.h>


void* thread_func(void* data)
{
cout <<"thread_func()"<<endl;
}

int main()
{
pthread_t p_threads;
pthread_create(&p_threads, NULL, thread_func, NULL);

return 0;
}


When I compiled it, I got an error on <stdlib.h>

In file included from mythread.cpp:3:

C:\\cygnus\\.........stdlib.h:103: parse error before 'unsigned'


Now if I flipped line 1 with line 3, ie., switched the include orders between <stdlib.h> and <iostream.h> to the following,

#include <stdlib.h>

#include <iostream.h>
#include <pthread.h>




The file compiled and ran fine.

That got me very curious, so I wrote another simple cpp file

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
cout << "test"<<endl;
return 0;
}


Now it doesn't matter the order of the #includes, the file compiled and ran fine.

I have no idea what's going on. Any help will be appreciated!
Since Windows doesn't support pthread in native, I think the cause is pthread.h, this header defines something conflicting with others. I don't think there is any problem to include pthread.h after all other headers.
I think that's it. Thanks!
closed account (zb0S216C)
pthread( ), I believe, is an abbreviated name for POSIX Thread. Windows doesn't support POSIX threads. For Windows, <process.h> should be used instead.

Wazzak
What happens if you use the modern C++ headers <iostream> and <cstdlib> instead of the old <iostream.h> and <stdlib.h> ?
Topic archived. No new replies allowed.