I am fairly a newbie in C, Could anyone help me ?
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <windows.h>
struct New
{
char a;
int b;
};
void *Print_Func (void* Ptr)
{
Sleep(5);
printf("%d\n",Ptr.a);
printf("%d\n",Ptr.b);
}
int main (void)
{
pthread_t Thread1;
while(1)
{
struct New Flag;
Flag.a=5;
Flag.b=1234567;
pthread_create(&Thread1,NULL,Print_Func,&Flag);
pthread_join(Thread1,NULL);
printf("\n");
}
system("pause>nul");
}
Why compiler always reports
error: request for member 'a' in something not a structure or union
error: request for member 'b' in something not a structure or union
Envir. : Windows7 C:B mingw32-gcc.exe
Thanks
pthread_create()because you do not change the value between threads and the threads don't modify it. Very often you need to pass a separate value to each thread because each thread has a slightly different task to do, and the argument tells it the difference. - Jonathan Leffler