Error Compiling C Code with Time and Date Functions.

Martin McCormick martin at
Tue Dec 9 21:32:35 UTC 2008

	I portedd some code I had written in FreeBSD unix over to
a new ubuntu-server system only to discover that none of the
time and date functions compile in Linux but do so under
FreeBSD. When referencing members of the structure timeptr such as

(timeptr->tm_year - 100), (timeptr->tm_mon) + 1,     timeptr->tm_mday);

	compilation finds an error every time. The following
fragment will produce the error:

    struct tm *timeptr;
    time_t elapsed_seconds; /*since midnight 1/1/70*/
    timeptr = localtime(&elapsed_seconds); /*fill structure*/
sprintf(newalarm,"alarms%02d%02d%02d", (timeptr->tm_year - 100), (timeptr->tm_mon) + 1,     timeptr->tm_mday);

	I actually ported over 8 small applications and all use
time and date and all fail to compile.

The error is:

"dereferencing pointer to incomplete type"

The headers I include are:

#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
#include <ctype.h>
#include <strings.h>
#include <sys/time.h>
#include <libgen.h>

	Any ideas on the easiest way to satisfy gcc?

	Thank you.

Martin McCormick

More information about the ubuntu-users mailing list