I'm writing a header, timedate.h, which begins as follows:
#ifndef _TIMEDATE_H_
#define _TIMEDATE_H_
int timetounixtime(int year, int month, int day, int hour, int minute, int second)
{
struct tm *time;
time->tm_year = year;
time->tm_mon = month;
time->tm_mday = day;
time->tm_hour = hour;
time->tm_min = minute;
time->tm_sec = second;
return mktime(time);
}
/*...*/
#endif
And is then included in one of my main .c files as follows:
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include "timedate.h"
int main(int argv, char **argc)
{
/*...*/
}
It seems to me that this should work since time.h is included in the main code before timedate.h is called. However, when I make, I get the following errors:
XXXXXXXXXX$ make
gcc file2nav.c -o file2nav
In file included from file2nav.c:4:0:
timedate.h: In function ‘timetounixtime’:
timedate.h:10:7: error: dereferencing pointer to incomplete type
timedate.h:11:7: error: dereferencing pointer to incomplete type
timedate.h:12:7: error: dereferencing pointer to incomplete type
timedate.h:13:7: error: dereferencing pointer to incomplete type
timedate.h:14:7: error: dereferencing pointer to incomplete type
timedate.h:15:7: error: dereferencing pointer to incomplete type
Can you help me understand what's going on? I note that if I #include <time.h>
in timedate.h, the error goes away...But why? It's already included in file2nav.c.