This question already has an answer here:
- Timespec :struct type Error c2011 4 answers
While executing a Pthread program in C using Visual Studio 2015, I got the following error:
Error C2011 'timespec': 'struct' type redefinition
The following is my code:
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
void *calculator(void *parameter);
int main(/*int *argc,char *argv[]*/)
{
pthread_t thread_obj;
pthread_attr_t thread_attr;
char *First_string = "abc"/*argv[1]*/;
pthread_attr_init(&thread_attr);
pthread_create(&thread_obj,&thread_attr,calculator,First_string);
}
void *calculator(void *parameter)
{
int x=atoi((char*)parameter);
printf("x=%d", x);
}
The pthread.h
header file contains the following code related to timespec:
#if !defined(HAVE_STRUCT_TIMESPEC)
#define HAVE_STRUCT_TIMESPEC
#if !defined(_TIMESPEC_DEFINED)
#define _TIMESPEC_DEFINED
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#endif /* _TIMESPEC_DEFINED */
#endif /* HAVE_STRUCT_TIMESPEC */
No other header file which I use uses the timespec
struct, so there is no chance of redefining. There is no chance of a corrupted header file because it has been downloaded from pthread opensource website.